diff options
Diffstat (limited to 'RepSys')
-rw-r--r-- | RepSys/commands/putsrpm.py | 65 | ||||
-rw-r--r-- | RepSys/rpmutil.py | 76 |
2 files changed, 83 insertions, 58 deletions
diff --git a/RepSys/commands/putsrpm.py b/RepSys/commands/putsrpm.py index 0717cd6..5256cba 100644 --- a/RepSys/commands/putsrpm.py +++ b/RepSys/commands/putsrpm.py @@ -1,12 +1,4 @@ #!/usr/bin/python -# -# This program will append a release to the Conectiva Linux package -# repository system. It's meant to be a startup system to include -# pre-packaged SRPMS in the repository, thus, you should not commit -# packages over an ongoing package structure (with changes in current/ -# directory and etc). Also, notice that packages must be included in -# cronological order. -# from RepSys import Error from RepSys.command import * from RepSys.layout import package_url @@ -15,47 +7,48 @@ import getopt import sys, os HELP = """\ -*** WARNING --- You probably SHOULD NOT use this program! --- WARNING *** +Usage: repsys putsrpm [OPTIONS] SOURCERPMS -Usage: repsys putsrpm [OPTIONS] REPPKGURL +Will import source RPMs into the SVN repository. + +If the package was already imported, it will add the new files and remove +those not present in the source RPM. Options: - -n Append package name to provided URL - -l LOG Use log when commiting changes + -m LOG Log message used when commiting changes + -t Create version-release tag on releases/ + -b NAME The distribution branch to place it + -d URL The URL of base directory where packages will be placed + -c URL The URL of the base directory where the changelog will be + placed + -s Don't strip the changelog from the spec -h Show this message Examples: - repsys putsrpm file://svn/cnc/snapshot/foo /cnc/d/SRPMS/foo-1.0.src.rpm + repsys putsrpm pkg/SRPMS/pkg-2.0-1.src.rpm + repsys putsrpm -b 2009.1 foo-1.1-1.src.rpm """ def parse_options(): parser = OptionParser(help=HELP) - parser.add_option("-l", dest="log", default="") - parser.add_option("-n", dest="appendname", action="store_true") + parser.add_option("-l", dest="logmsg", default="") + parser.add_option("-t", dest="markrelease", action="store_true", + default=False) + parser.add_option("-s", dest="striplog", action="store_false", + default=True) + parser.add_option("-b", dest="branch", type="string", default=None) + parser.add_option("-d", dest="baseurl", type="string", default=None) + parser.add_option("-c", dest="baseold", type="string", default=None) opts, args = parser.parse_args() - if len(args) != 2: - raise Error, "invalid arguments" - opts.pkgdirurl = package_url(args[0], mirrored=False) - opts.srpmfile = args[1] + opts.srpmfiles = args return opts -def put_srpm_cmd(pkgdirurl, srpmfile, appendname=0, log=""): - if os.path.isdir(srpmfile): - dir = srpmfile - for entry in os.listdir(dir): - if entry[-8:] == ".src.rpm": - sys.stderr.write("Putting %s... " % entry) - sys.stderr.flush() - entrypath = os.path.join(dir, entry) - try: - put_srpm(pkgdirurl, entrypath, appendname, log) - sys.stderr.write("done\n") - except Error, e: - sys.stderr.write("error: %s\n" % str(e)) - else: - put_srpm(pkgdirurl, srpmfile, appendname, log) - - +def put_srpm_cmd(srpmfiles, markrelease=False, striplog=True, branch=None, + baseurl=None, baseold=None, logmsg=None): + for path in srpmfiles: + put_srpm(path, markrelease, striplog, branch, baseurl, baseold, + logmsg) + def main(): do_command(parse_options, put_srpm_cmd) diff --git a/RepSys/rpmutil.py b/RepSys/rpmutil.py index ab85fab..0ca6bdb 100644 --- a/RepSys/rpmutil.py +++ b/RepSys/rpmutil.py @@ -1,9 +1,8 @@ #!/usr/bin/python from RepSys import Error, config -from RepSys import mirror, layout +from RepSys import mirror, layout, log from RepSys.svn import SVN from RepSys.simplerpm import SRPM -from RepSys.log import specfile_svn2rpm from RepSys.util import execcmd from RepSys.command import default_parent import rpm @@ -105,7 +104,7 @@ def get_srpm(pkgdirurl, spec = speclist[0] if svnlog: submit = not not revision - specfile_svn2rpm(pkgdirurl, spec, revision, submit=submit, + log.specfile_svn2rpm(pkgdirurl, spec, revision, submit=submit, template=template, macros=macros, exported=tmpdir) for script in scripts: #FIXME revision can be "None" @@ -171,36 +170,41 @@ def patch_spec(pkgdirurl, patchfile, log=""): if os.path.isdir(tmpdir): shutil.rmtree(tmpdir) -def put_srpm(pkgdirurl, srpmfile, appendname=0, log=""): - srpm = SRPM(srpmfile) - if appendname: - pkgdirurl = "/".join([pkgdirurl, srpm.name]) +def put_srpm(srpmfile, markrelease=False, striplog=True, branch=None, + baseurl=None, baseold=None, logmsg=None): svn = SVN() + srpm = SRPM(srpmfile) tmpdir = tempfile.mktemp() + if baseurl: + pkgurl = mirror._joinurl(baseurl, srpm.name) + else: + pkgurl = layout.package_url(srpm.name, distro=branch, + mirrored=False) + print "Importing package to %s" % pkgurl try: if srpm.epoch: version = "%s:%s" % (srpm.epoch, srpm.version) else: version = srpm.version - versionurl = "/".join([pkgdirurl, "releases", version]) + versionurl = "/".join([pkgurl, "releases", version]) releaseurl = "/".join([versionurl, srpm.release]) + currenturl = os.path.join(tmpdir, "current") #FIXME when pre-commit hook fails, there's no clear way to know # what happened - ret = svn.mkdir(pkgdirurl, noerror=1, log="Created package directory") - if ret: - svn.checkout(pkgdirurl, tmpdir) + ret = svn.mkdir(pkgurl, noerror=1, log="Created package directory") + if ret or not svn.ls(currenturl, noerror=1): + svn.checkout(pkgurl, tmpdir) svn.mkdir(os.path.join(tmpdir, "releases")) - svn.mkdir(os.path.join(tmpdir, "releases", version)) - svn.mkdir(os.path.join(tmpdir, "current")) - svn.mkdir(os.path.join(tmpdir, "current", "SPECS")) - svn.mkdir(os.path.join(tmpdir, "current", "SOURCES")) + svn.mkdir(currenturl) + svn.mkdir(os.path.join(currenturl, "SPECS")) + svn.mkdir(os.path.join(currenturl, "SOURCES")) #svn.commit(tmpdir,log="Created package structure.") version_exists = 1 currentdir = os.path.join(tmpdir, "current") else: if svn.ls(releaseurl, noerror=1): raise Error, "release already exists" - svn.checkout("/".join([pkgdirurl, "current"]), tmpdir) + svn.checkout("/".join([pkgurl, "current"]), tmpdir) svn.mkdir(versionurl, noerror=1, log="Created directory for version %s." % version) currentdir = tmpdir @@ -254,22 +258,50 @@ def put_srpm(pkgdirurl, srpmfile, appendname=0, log=""): if os.path.isdir(unpackdir): shutil.rmtree(unpackdir) - svn.commit(tmpdir, log=log) + if striplog: + specs = glob.glob(os.path.join(specsdir, "*.spec")) + if not specs: + raise Error, "no spec file fount on %s" % specsdir + specpath = specs[0] + fspec = open(specpath) + spec, chlog = log.split_spec_changelog(fspec) + chlog.seek(0) + fspec.close() + oldurl = baseold or config.get("log", "oldurl") + pkgoldurl = mirror._joinurl(oldurl, srpm.name) + svn.mkdir(pkgoldurl, noerror=1, + log="created old log directory for %s" % srpm.name) + logtmp = tempfile.mktemp() + try: + svn.checkout(pkgoldurl, logtmp) + miscpath = os.path.join(logtmp, "log") + fmisc = open(miscpath, "w+") + fmisc.writelines(chlog) + fmisc.close() + svn.add(miscpath) + svn.commit(logtmp, + log="imported old log for %s" % srpm.name) + finally: + if os.path.isdir(logtmp): + shutil.rmtree(logtmp) + svn.commit(tmpdir, + log=logmsg or ("imported package %s" % srpm.name)) finally: if os.path.isdir(tmpdir): shutil.rmtree(tmpdir) # Do revision and pristine tag copies - pristineurl = layout.checkout_url(pkgdirurl, pristine=True) + pristineurl = layout.checkout_url(pkgurl, pristine=True) svn.remove(pristineurl, noerror=1, log="Removing previous pristine/ directory.") - currenturl = layout.checkout_url(pkgdirurl) + currenturl = layout.checkout_url(pkgurl) svn.copy(currenturl, pristineurl, log="Copying release %s-%s to pristine/ directory." % (version, srpm.release)) - svn.copy(currenturl, releaseurl, - log="Copying release %s-%s to releases/ directory." % - (version, srpm.release)) + if markrelease: + svn.copy(currenturl, releaseurl, + log="Copying release %s-%s to releases/ directory." % + (version, srpm.release)) def create_package(pkgdirurl, log="", verbose=0): svn = SVN() |