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/commands/markrelease.py | 2 +- RepSys/commands/sync.py | 31 ++++++++++++++++++++++++ RepSys/rpm.py | 19 --------------- RepSys/rpmutil.py | 54 +++++++++++++++++++++++++++++++++++++++++- RepSys/simplerpm.py | 19 +++++++++++++++ RepSys/svn.py | 2 ++ repsys | 1 + repsys.spec | 2 +- 8 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 RepSys/commands/sync.py delete mode 100644 RepSys/rpm.py create mode 100644 RepSys/simplerpm.py diff --git a/RepSys/commands/markrelease.py b/RepSys/commands/markrelease.py index 9e52a31..440775b 100644 --- a/RepSys/commands/markrelease.py +++ b/RepSys/commands/markrelease.py @@ -9,7 +9,7 @@ # from RepSys import Error from RepSys.command import * -from RepSys.rpm import SRPM +from RepSys.simplerpm import SRPM from RepSys.rpmutil import mark_release from RepSys.util import get_auth import getopt diff --git a/RepSys/commands/sync.py b/RepSys/commands/sync.py new file mode 100644 index 0000000..42ede8d --- /dev/null +++ b/RepSys/commands/sync.py @@ -0,0 +1,31 @@ +#!/usr/bin/python +from RepSys.command import * +from RepSys.rpmutil import sync + +HELP = """\ +Usage: repsys sync + +Will add or removed from the working copy new files added or removed +from the spec file. + +"No changes are commited." + +Options: + --dry-run Print results without changing the working copy + -h Show this message + +Examples: + repsys sync +""" + +def parse_options(): + parser = OptionParser(help=HELP) + parser.add_option("--dry-run", dest="dryrun", default=False, + action="store_true") + opts, args = parser.parse_args() + if len(args): + opts.target = args[0] + return opts + +def main(): + do_command(parse_options, sync) diff --git a/RepSys/rpm.py b/RepSys/rpm.py deleted file mode 100644 index d448c5f..0000000 --- a/RepSys/rpm.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/python -from RepSys.util import execcmd - -class SRPM: - def __init__(self, filename): - self.filename = filename - self._getinfo() - - def _getinfo(self): - cmdstr = "rpm -qp --qf '%%{name} %%{epoch} %%{release} %%{version}' %s" - status, output = execcmd(cmdstr % self.filename) - self.name, self.epoch, self.release, self.version = output.split() - if self.epoch == "(none)": - self.epoch = None - - def unpack(self, topdir): - execcmd("rpm -i --define '_topdir %s' %s" % (topdir, self.filename)) - -# vim:et:ts=4:sw=4 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) diff --git a/RepSys/simplerpm.py b/RepSys/simplerpm.py new file mode 100644 index 0000000..d448c5f --- /dev/null +++ b/RepSys/simplerpm.py @@ -0,0 +1,19 @@ +#!/usr/bin/python +from RepSys.util import execcmd + +class SRPM: + def __init__(self, filename): + self.filename = filename + self._getinfo() + + def _getinfo(self): + cmdstr = "rpm -qp --qf '%%{name} %%{epoch} %%{release} %%{version}' %s" + status, output = execcmd(cmdstr % self.filename) + self.name, self.epoch, self.release, self.version = output.split() + if self.epoch == "(none)": + self.epoch = None + + def unpack(self, topdir): + execcmd("rpm -i --define '_topdir %s' %s" % (topdir, self.filename)) + +# vim:et:ts=4:sw=4 diff --git a/RepSys/svn.py b/RepSys/svn.py index a13db8b..b4ad4e9 100644 --- a/RepSys/svn.py +++ b/RepSys/svn.py @@ -187,6 +187,8 @@ class SVN: cmd = ["status", path] if kwargs.get("verbose"): cmd.append("-v") + if kwargs.get("noignore"): + cmd.append("--no-ignore") status, output = self._execsvn(*cmd, **kwargs) if status == 0: return [x.split() for x in output.splitlines()] diff --git a/repsys b/repsys index 2157308..c2f18f4 100755 --- a/repsys +++ b/repsys @@ -12,6 +12,7 @@ Usage: repsys COMMAND [COMMAND ARGUMENTS] Useful commands: co ci + sync submit create getspec diff --git a/repsys.spec b/repsys.spec index 81e251a..edb0cf8 100644 --- a/repsys.spec +++ b/repsys.spec @@ -12,7 +12,7 @@ Buildrequires: python-devel BuildRoot: %{_tmppath}/%{name}-%{version}-root BuildRequires: python BuildRequires: python-devel -Requires: python-cheetah +Requires: python-cheetah python-rpm %description Tools for Mandriva Linux repository access and management. -- cgit v1.2.1