From 928b0bed6fff9a002fcd10533fd1fa464e1bc10b Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Thu, 3 May 2007 21:03:27 +0000 Subject: Added one cheap copy of the sync subcommand from mdvsys. It required two sensitive changes: - in order to parse the spec file, "rpm" module was used, so this is the brand new package dependency; and - as RepSys already had one "rpm" module, we had to rename it to "simplerpm" in order to allow access to the module from python-rpm (I think py2.4 is still used a lot so we can't use absolute imports) --- RepSys/rpmutil.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'RepSys/rpmutil.py') diff --git a/RepSys/rpmutil.py b/RepSys/rpmutil.py index 12a8226..651d19f 100644 --- a/RepSys/rpmutil.py +++ b/RepSys/rpmutil.py @@ -2,9 +2,10 @@ from RepSys import Error, config, RepSysTree from RepSys import mirror from RepSys.svn import SVN -from RepSys.rpm import SRPM +from RepSys.simplerpm import SRPM from RepSys.log import specfile_svn2rpm from RepSys.util import execcmd +import rpm import tempfile import shutil import glob @@ -363,6 +364,57 @@ def checkout(pkgdirurl, path=None, revision=None): print "checking out from mirror", current svn.checkout(current, path, rev=revision, show=1) +def sync(dryrun=False): + svn = SVN(noauth=True) + cwd = os.getcwd() + dirname = os.path.basename(cwd) + if dirname == "SPECS" or dirname == "SOURCES": + topdir = os.pardir + else: + topdir = "" + specsdir = os.path.join(topdir, "SPECS/") + sourcesdir = os.path.join(topdir, "SOURCES/") + for path in (specsdir, sourcesdir): + if not os.path.isdir(path): + raise Error, "%s directory not found" % path + specs = glob.glob(os.path.join(specsdir, "*.spec")) + if not specs: + raise Error, "no .spec files found in %s" % specsdir + specpath = specs[0] # FIXME better way? + try: + spec = rpm.TransactionSet().parseSpec(specpath) + except rpm.error, e: + raise Error, "could not load spec file: %s" % e + sources = [name for name, x, y in spec.sources()] + sourcesst = dict((os.path.basename(path), st) + for st, path in svn.status(sourcesdir, noignore=True)) + toadd = [] + for source in sources: + sourcepath = os.path.join(sourcesdir, source) + if sourcesst.get(source): + if os.path.isfile(sourcepath): + toadd.append(sourcepath) + else: + sys.stderr.write("warning: %s not found\n" % sourcepath) + # rm entries not found in sources and still in svn + found = os.listdir(sourcesdir) + toremove = [] + for entry in found: + if entry == ".svn": + continue + status = sourcesst.get(entry) + if status is None and entry not in sources: + path = os.path.join(sourcesdir, entry) + toremove.append(path) + for path in toremove: + print "D\t%s" % path + if not dryrun: + svn.remove(path, local=True) + for path in toadd: + print "A\t%s" % path + if not dryrun: + svn.add(path, local=True) + def commit(target=".", message=None): svn = SVN(noauth=True) info = svn.info2(target) -- cgit v1.2.1