Exemplo n.º 1
0
def checkout(pkgdirurl,
             path=None,
             revision=None,
             branch=None,
             distro=None,
             backports=None,
             spec=False):
    o_pkgdirurl = pkgdirurl
    pkgdirurl = layout.package_url(o_pkgdirurl,
                                   distro=distro,
                                   backports=backports)
    append = None
    if spec:
        append = "SPECS"
    current = layout.checkout_url(pkgdirurl,
                                  branch=branch,
                                  backports=backports,
                                  append_path=append)
    if path is None:
        path = layout.package_name(pkgdirurl)
    mirror.info(current, write=True)
    svn = detectVCS(pkgdirurl)
    svn.checkout(current, path, rev=revision, show=1)
    if not spec:
        binrepo.download_binaries(path)
Exemplo n.º 2
0
def clone(pkgdirurl,
          path=None,
          revision=None,
          branch=None,
          distro=None,
          backports=None,
          spec=False,
          fullnames=True,
          bindownload=True):
    o_pkgdirurl = pkgdirurl
    pkgdirurl = layout.package_url(o_pkgdirurl,
                                   distro=distro,
                                   backports=backports)
    append = None
    if spec:
        append = "SPECS"
    current = layout.checkout_url(pkgdirurl,
                                  branch=branch,
                                  backports=backports,
                                  append_path=append)
    if path is None:
        path = layout.package_name(pkgdirurl)
    mirror.info(current, write=True)
    vcs = detectVCS(pkgdirurl)

    if type(vcs) == SVN:
        git = GITSVN(url=pkgdirurl)
    else:
        git = vcs
    git.clone(current, path, fullnames=fullnames)
    if not spec and bindownload:
        binrepo.download_binaries(path)
Exemplo n.º 3
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.defaults["mode"] = "current"
    parser.defaults["version"] = None
    parser.defaults["release"] = None
    parser.defaults["revision"] = None
    parser.defaults["submit"] = False
    callback_options = dict(action="callback", callback=mode_callback,
                            type="string", dest="__ignore")
    parser.add_option("-c", callback_kwargs={"mode": "current"}, nargs=0,
                      **callback_options)
    parser.add_option("-p", callback_kwargs={"mode": "pristine"}, nargs=0,
                      **callback_options)
    parser.add_option("-r", callback_kwargs={"mode": "revision"}, nargs=1,
                      **callback_options)
    parser.add_option("-v", callback_kwargs={"mode": "version"}, nargs=1,
                      **callback_options)
    parser.add_option("-t", dest="targetdirs", action="append", default=[])
    parser.add_option("-s", dest="scripts", action="append", default=[])
    parser.add_option("-P", dest="packager", default="")
    parser.add_option("-n", dest="revname", action="store_true")
    parser.add_option("-l", dest="svnlog", action="store_true")
    parser.add_option("-T", dest="template", type="string", default=None)
    parser.add_option("-M", "--no-mirror", action="callback",
            callback=disable_mirror)
    parser.add_option("-d", "--distro", type="string", default=None)
    parser.add_option("--strict", dest="strict", default=False,
            action="store_true")
    opts, args = parser.parse_args()
    del opts.__ignore
    if len(args) != 1:
        raise Error, "invalid arguments"
    opts.pkgdirurl = package_url(args[0])
    opts.verbose = 1
    return opts
Exemplo n.º 4
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.defaults["mode"] = "current"
    parser.defaults["version"] = None
    parser.defaults["release"] = None
    parser.defaults["revision"] = None
    parser.defaults["submit"] = False
    callback_options = dict(action="callback", callback=mode_callback,
                            type="string", dest="__ignore")
    parser.add_option("-c", callback_kwargs={"mode": "current"}, nargs=0,
                      **callback_options)
    parser.add_option("-p", callback_kwargs={"mode": "pristine"}, nargs=0,
                      **callback_options)
    parser.add_option("-r", callback_kwargs={"mode": "revision"}, nargs=1,
                      **callback_options)
    parser.add_option("-v", callback_kwargs={"mode": "version"}, nargs=1,
                      **callback_options)
    parser.add_option("-t", dest="targetdirs", action="append", default=[])
    parser.add_option("-s", dest="scripts", action="append", default=[])
    parser.add_option("-P", dest="packager", default="")
    parser.add_option("-n", dest="revname", action="store_true")
    parser.add_option("-l", dest="svnlog", action="store_true")
    parser.add_option("-T", dest="template", type="string", default=None)
    parser.add_option("-M", "--no-mirror", action="callback",
            callback=disable_mirror)
    parser.add_option("--strict", dest="strict", default=False,
            action="store_true")
    opts, args = parser.parse_args()
    del opts.__ignore
    if len(args) != 1:
        raise Error, "invalid arguments"
    opts.pkgdirurl = package_url(args[0])
    opts.verbose = 1
    return opts
Exemplo n.º 5
0
def obsolete(pkgdirurl,
             branch=None,
             distro=None,
             backports=None,
             commit=False,
             log=None):
    o_pkgdirurl = pkgdirurl
    pkgdirurl = layout.package_url(o_pkgdirurl,
                                   distro=distro,
                                   backports=backports)
    pkgdest = layout.package_url(o_pkgdirurl,
                                 obsolete=True,
                                 backports=backports)
    svn = detectVCS(pkgdirurl)
    svn.mv(pkgdirurl, pkgdest, message=log)
    if commit:
        svn.commit(path, log=log)
Exemplo n.º 6
0
def parse_options():
    parser = OptionParser(help=HELP)
    opts, args = parser.parse_args()
    if len(args) != 1:
        raise Error("invalid arguments")
    opts.pkgdirurl = package_url(args[0], mirrored=False)
    opts.verbose = 1  # Unconfigurable
    return opts
Exemplo n.º 7
0
def parse_options():
    parser = OptionParser(help=HELP)
    opts, args = parser.parse_args()
    if len(args) != 1:
        raise Error, "invalid arguments"
    opts.pkgdirurl = package_url(args[0], mirrored=False)
    opts.verbose = 1 # Unconfigurable
    return opts
Exemplo n.º 8
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-l", dest="log", default="")
    opts, args = parser.parse_args()
    if len(args) != 2:
        raise Error, "invalid arguments"
    opts.pkgdirurl = package_url(args[0], mirrored=False)
    opts.patchfile = args[1]
    return opts
Exemplo n.º 9
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-l", dest="log", default="")
    opts, args = parser.parse_args()
    if len(args) != 2:
        raise Error, "invalid arguments"
    opts.pkgdirurl = package_url(args[0], mirrored=False)
    opts.patchfile = args[1]
    return opts
Exemplo n.º 10
0
def clone(pkgdirurl, path=None, branch=None,
        distro=None):
    o_pkgdirurl = pkgdirurl
    pkgdirurl = layout.package_url(o_pkgdirurl, distro=distro)
    current = layout.checkout_url(pkgdirurl, branch=branch)
    if path is None:
        path = layout.package_name(pkgdirurl)
    mirror.info(current)
    git = GIT()
    git.clone(current, path, show=1)
Exemplo n.º 11
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-t", dest="targetdir", default=".")
    parser.add_option("-M", "--no-mirror", action="callback",
            callback=disable_mirror)
    opts, args = parser.parse_args()
    if len(args) != 1:
        raise Error("invalid arguments")
    opts.pkgdirurl = package_url(args[0])
    return opts
Exemplo n.º 12
0
def clone(pkgdirurl, path=None, branch=None,
        distro=None):
    o_pkgdirurl = pkgdirurl
    pkgdirurl = layout.package_url(o_pkgdirurl, distro=distro)
    current = layout.checkout_url(pkgdirurl, branch=branch)
    if path is None:
        path = layout.package_name(pkgdirurl)
    mirror.info(current)
    git = GIT()
    git.clone(current, path, show=1)
Exemplo n.º 13
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-t", dest="targetdir", default=".")
    parser.add_option("-M", "--no-mirror", action="callback",
            callback=disable_mirror)
    opts, args = parser.parse_args()
    if len(args) != 1:
        raise Error, "invalid arguments"
    opts.pkgdirurl = package_url(args[0])
    return opts
Exemplo n.º 14
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-a", dest="all", action="store_true")
    parser.add_option("-s", dest="show", action="store_true")
    parser.add_option("-M", "--no-mirror", action="disable_mirror")
    opts, args = parser.parse_args()
    if len(args) != 1:
        raise Error, "invalid arguments"
    opts.pkgdirurl = package_url(args[0])
    opts.verbose = 1 # Unconfigurable
    return opts
Exemplo n.º 15
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-a", dest="all", action="store_true")
    parser.add_option("-s", dest="show", action="store_true")
    parser.add_option("-M", "--no-mirror", action="disable_mirror")
    opts, args = parser.parse_args()
    if len(args) != 1:
        raise Error, "invalid arguments"
    opts.pkgdirurl = package_url(args[0])
    opts.verbose = 1  # Unconfigurable
    return opts
Exemplo n.º 16
0
def parse_options():
    parser = OptionParser(help=HELP)
    opts, args = parser.parse_args()
    if len(args) == 2:
        pkgdirurl, revision = args
    elif len(args) == 1:
        pkgdirurl, revision = "", args[0]
    else:
        raise Error("invalid arguments")
    opts.pkgdirurl = package_url(pkgdirurl, mirrored=False)
    opts.revision = re.compile(r".*?(\d+).*").sub(r"\1", revision)
    return opts
Exemplo n.º 17
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.defaults["version"] = None
    parser.defaults["release"] = None
    parser.add_option("-v",
                      action="callback",
                      callback=version_callback,
                      nargs=1,
                      type="string",
                      dest="__ignore")
    parser.add_option("-r", dest="revision")
    parser.add_option("-f", dest="filename")
    parser.add_option("-n", dest="appendname", action="store_true")
    opts, args = parser.parse_args()

    if len(args) != 1:
        raise Error, "invalid arguments"

    opts.pkgdirurl = package_url(args[0], mirrored=False)

    filename = opts.filename
    appendname = opts.appendname
    del opts.filename, opts.appendname, opts.__ignore

    if filename:
        if not os.path.isfile(filename):
            raise Error, "file not found: " + filename
        if not opts.revision:
            basename = os.path.basename(filename)
            end = basename.find(":")
            if basename[0] != "@" or end == -1:
                raise Error, "couldn't guess revision from filename"
            opts.revision = basename[1:end]
        srpm = None
        if not opts.version:
            srpm = SRPM(filename)
            if srpm.epoch:
                opts.version = "%s:%s" % (srpm.epoch, srpm.version)
            else:
                opts.version = srpm.version
            opts.release = srpm.release
        if appendname:
            if not srpm:
                srpm = SRPM(filename)
            opts.pkgdirurl = "/".join([opts.pkgdirurl, srpm.name])
    elif appendname:
        raise Error, "option -n requires option -f"
    elif not opts.revision:
        raise Error, "no revision provided"
    elif not opts.version:
        raise Error, "no version provided"
    #get_auth()
    return opts
Exemplo n.º 18
0
def parse_options():
    parser = OptionParser(help=HELP)
    opts, args = parser.parse_args()
    if len(args) == 2:
        pkgdirurl, revision = args
    elif len(args) == 1:
        pkgdirurl, revision = "", args[0]
    else:
        raise Error, "invalid arguments"
    opts.pkgdirurl = package_url(pkgdirurl, mirrored=False)
    opts.revision = re.compile(r".*?(\d+).*").sub(r"\1", revision)
    return opts
Exemplo n.º 19
0
def checkout(pkgdirurl, path=None, revision=None, branch=None,
        distro=None, spec=False):
    o_pkgdirurl = pkgdirurl
    pkgdirurl = layout.package_url(o_pkgdirurl, distro=distro)
    append = None
    if spec:
        append = "SPECS"
    current = layout.checkout_url(pkgdirurl, branch=branch,
            append_path=append)
    if path is None:
        path = layout.package_name(pkgdirurl)
    mirror.info(current, write=True)
    svn = SVN()
    svn.checkout(current, path, rev=revision, show=1)
Exemplo n.º 20
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-r", dest="revision")
    parser.add_option("-n", dest="size", type="int")
    parser.add_option("-T", "--template", dest="template", type="string")
    parser.add_option("-o", dest="oldlog", default=False, action="store_true")
    parser.add_option("-p", dest="usespec", default=False, action="store_true")
    parser.add_option("-s", dest="sort", default=False, action="store_true")
    parser.add_option("-M", "--no-mirror", action="callback", callback=disable_mirror)
    opts, args = parser.parse_args()
    if len(args) != 1:
        raise Error, "invalid arguments"
    opts.pkgdirurl = layout.package_url(args[0])
    return opts
Exemplo n.º 21
0
def checkout(pkgdirurl, path=None, revision=None, branch=None,
        distro=None, spec=False):
    o_pkgdirurl = pkgdirurl
    pkgdirurl = layout.package_url(o_pkgdirurl, distro=distro)
    append = None
    if spec:
        append = "SPECS"
    current = layout.checkout_url(pkgdirurl, branch=branch,
            append_path=append)
    if path is None:
        path = layout.package_name(pkgdirurl)
    mirror.info(current)
    svn = SVN()
    svn.checkout(current, path, rev=revision, show=1)
def parse_options():
    parser = OptionParser(help=HELP)
    parser.defaults["version"] = None
    parser.defaults["release"] = None
    parser.add_option("-v", action="callback", callback=version_callback,
            nargs=1, type="string", dest="__ignore")
    parser.add_option("-r", dest="revision")
    parser.add_option("-f", dest="filename")
    parser.add_option("-n", dest="appendname", action="store_true")
    opts, args = parser.parse_args()

    if len(args) != 1:
        raise Error, "invalid arguments"

    opts.pkgdirurl = package_url(args[0], mirrored=False)

    filename = opts.filename
    appendname = opts.appendname
    del opts.filename, opts.appendname, opts.__ignore

    if filename:
        if not os.path.isfile(filename):
            raise Error, "file not found: "+filename
        if not opts.revision:
            basename = os.path.basename(filename)
            end = basename.find(":")
            if basename[0] != "@" or end == -1:
                raise Error, "couldn't guess revision from filename"
            opts.revision = basename[1:end]
        srpm = None
        if not opts.version:
            srpm = SRPM(filename)
            if srpm.epoch:
                opts.version = "%s:%s" % (srpm.epoch, srpm.version)
            else:
                opts.version = srpm.version
            opts.release = srpm.release
        if appendname:
            if not srpm:
                srpm = SRPM(filename)
            opts.pkgdirurl = "/".join([opts.pkgdirurl, srpm.name])
    elif appendname:
        raise Error, "option -n requires option -f"
    elif not opts.revision:
        raise Error, "no revision provided"
    elif not opts.version:
        raise Error, "no version provided"
    #get_auth()
    return opts
Exemplo n.º 23
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-v", dest="verbose", action="store_true",
            default=False)
    parser.add_option("-l", "--limit", dest="limit", type="int",
            default=None)
    parser.add_option("-r", dest="revision", type="string", default=None)
    parser.add_option("-M", "--no-mirror", action="callback",
            callback=disable_mirror)
    opts, args = parser.parse_args()
    if len(args):
        opts.pkgdirurl = package_url(args[0])
    else:
        parser.error("log requires a package name")
    return opts
Exemplo n.º 24
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-v", dest="verbose", action="store_true", default=False)
    parser.add_option("-l", "--limit", dest="limit", type="int", default=None)
    parser.add_option("-r", dest="revision", type="string", default=None)
    parser.add_option("-M",
                      "--no-mirror",
                      action="callback",
                      callback=disable_mirror)
    opts, args = parser.parse_args()
    if len(args):
        opts.pkgdirurl = package_url(args[0])
    else:
        parser.error("log requires a package name")
    return opts
Exemplo n.º 25
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.add_option("-r", dest="revision")
    parser.add_option("-n", dest="size", type="int")
    parser.add_option("-T", "--template", dest="template", type="string")
    parser.add_option("-o", dest="oldlog", default=False, action="store_true")
    parser.add_option("-p", dest="usespec", default=False, action="store_true")
    parser.add_option("-s", dest="sort", default=False, action="store_true")
    parser.add_option("-M",
                      "--no-mirror",
                      action="callback",
                      callback=disable_mirror)
    opts, args = parser.parse_args()
    if len(args) != 1:
        raise Error, "invalid arguments"
    opts.pkgdirurl = layout.package_url(args[0])
    return opts
Exemplo n.º 26
0
def put_srpm(srpmfile,
             markrelease=False,
             striplog=True,
             branch=None,
             baseurl=None,
             baseold=None,
             logmsg=None,
             rename=True):
    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([pkgurl, "releases", version])
        releaseurl = "/".join([versionurl, srpm.release])
        currenturl = "/".join([pkgurl, "current"])
        currentdir = os.path.join(tmpdir, "current")
        #FIXME when pre-commit hook fails, there's no clear way to know
        # what happened
        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(currentdir)
            svn.mkdir(os.path.join(currentdir, "SPECS"))
            svn.mkdir(os.path.join(currentdir, "SOURCES"))
            #svn.commit(tmpdir,log="Created package structure.")
            version_exists = 1
        else:
            if svn.ls(releaseurl, noerror=1):
                raise Error, "release already exists"
            svn.checkout("/".join([pkgurl, "current"]), tmpdir)
            svn.mkdir(versionurl,
                      noerror=1,
                      log="Created directory for version %s." % version)
            currentdir = tmpdir

        specsdir = os.path.join(currentdir, "SPECS")
        sourcesdir = os.path.join(currentdir, "SOURCES")

        unpackdir = tempfile.mktemp()
        os.mkdir(unpackdir)
        try:
            srpm.unpack(unpackdir)

            uspecsdir = os.path.join(unpackdir, "SPECS")
            usourcesdir = os.path.join(unpackdir, "SOURCES")

            uspecsentries = os.listdir(uspecsdir)
            usourcesentries = os.listdir(usourcesdir)
            specsentries = os.listdir(specsdir)
            sourcesentries = os.listdir(sourcesdir)

            # Remove old entries
            for entry in [x for x in specsentries if x not in uspecsentries]:
                if entry == ".svn":
                    continue
                entrypath = os.path.join(specsdir, entry)
                os.unlink(entrypath)
                svn.remove(entrypath)
            for entry in [
                    x for x in sourcesentries if x not in usourcesentries
            ]:
                if entry == ".svn":
                    continue
                entrypath = os.path.join(sourcesdir, entry)
                os.unlink(entrypath)
                svn.remove(entrypath)

            # Copy all files
            execcmd(["cp", "-rf", uspecsdir, currentdir])
            execcmd(["cp", "-rf", usourcesdir, currentdir])

            # Add new entries
            for entry in [x for x in uspecsentries if x not in specsentries]:
                entrypath = os.path.join(specsdir, entry)
                svn.add(entrypath)
            for entry in [
                    x for x in usourcesentries if x not in sourcesentries
            ]:
                entrypath = os.path.join(sourcesdir, entry)
                svn.add(entrypath)
        finally:
            if os.path.isdir(unpackdir):
                shutil.rmtree(unpackdir)

        specs = glob.glob(os.path.join(specsdir, "*.spec"))
        if not specs:
            raise Error, "no spec file found on %s" % specsdir
        if len(specs) > 1:
            raise Error, "more than one spec file found on %s" % specsdir
        specpath = specs[0]
        if rename:
            specfile = os.path.basename(specpath)
            specname = specfile[:-len(".spec")]
            if specname != srpm.name:
                newname = srpm.name + ".spec"
                newpath = os.path.join(specsdir, newname)
                sys.stderr.write("warning: renaming spec file to '%s' "
                                 "(use -n to disable it)\n" % (newname))
                os.rename(specpath, newpath)
                try:
                    svn.remove(specpath)
                except Error:
                    # file not tracked
                    svn.revert(specpath)
                svn.add(newpath)
                specpath = newpath

        if striplog:
            specpath = specpath
            fspec = open(specpath)
            spec, chlog = log.split_spec_changelog(fspec)
            fspec.close()
            fspec = open(specpath, "w")
            fspec.writelines(spec)
            fspec.close()
            chlog.seek(0, os.SEEK_END)
            if chlog.tell() != 0:
                chlog.seek(0)
                #FIXME move it to layout.py
                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(pkgurl, pristine=True)
    svn.remove(pristineurl,
               noerror=1,
               log="Removing previous pristine/ directory.")
    currenturl = layout.checkout_url(pkgurl)
    svn.copy(currenturl,
             pristineurl,
             log="Copying release %s-%s to pristine/ directory." %
             (version, srpm.release))
    if markrelease:
        svn.copy(currenturl,
                 releaseurl,
                 log="Copying release %s-%s to releases/ directory." %
                 (version, srpm.release))
Exemplo n.º 27
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.defaults["revision"] = None
    parser.add_option("-t", dest="target", default=None)
    parser.add_option("-l", action="callback", callback=list_targets)
    parser.add_option("-r", dest="revision", type="string", nargs=1)
    parser.add_option("-s", dest="submithost", type="string", nargs=1,
            default=None)
    parser.add_option("-p", dest="port", type="int", default=None)
    parser.add_option("-i", dest="sid", type="string", nargs=1,
            default=None)
    parser.add_option("-a", dest="atonce", action="store_true", default=False)
    parser.add_option("--distro", dest="distro", type="string",
            default=None)
    parser.add_option("--define", action="append", default=[])
    opts, args = parser.parse_args()
    if not args:
        name, url, rev = get_submit_info(".")
        if opts.revision is not None:
            rev = opts.revision
        args = ["%s@%s" % (url, str(rev))]
        print "Submitting %s at revision %s" % (name, rev)
        print "URL: %s" % url
    if opts.revision is not None:
        # backwards compatibility with the old -r usage
        if len(args) == 1:
            args[0] = args[0] + "@" + opts.revision
        else:
            raise Error, "can't use -r REV with more than one package name"
    del opts.revision
    if len(args) == 2:
        # prevent from using the old <name> <rev> syntax
        try:
            rev = int(args[1])
        except ValueError:
            # ok, it is a package name, let it pass
            pass
        else:
            raise Error, "the format <name> <revision> is deprecated, "\
                    "use <name>@<revision> instead"
    # expand group aliases
    expanded = []
    for nameurl in args:
        expanded.extend(expand_group(nameurl))
    if expanded != args:
        print "Submitting: %s" % " ".join(expanded)
        args = expanded
    # generate URLs for package names:
    opts.urls = [mirror.strip_username(
                    layout.package_url(nameurl, distro=opts.distro, mirrored=False))
            for nameurl in args]
    # find the revision if not specified:
    newurls = []
    for url in opts.urls:
        if not "@" in url:
            print "Fetching revision..."
            courl = layout.checkout_url(url)
            log = SVN().log(courl, limit=1)
            if not log:
                raise Error, "can't find a revision for %s" % courl
            ci = log[0]
            print "URL:", url
            print "Commit:",
            print "%d | %s" % (ci.revision, ci.author),
            if ci.lines:
                line = " ".join(ci.lines).strip()
                if len(line) > 57:
                    line = line[:57] + "..."
                print "| %s" % line,
            print
            url = url + "@" + str(ci.revision)
        newurls.append(url)
    opts.urls[:] = newurls
    # choose a target if not specified:
    if opts.target is None and opts.distro is None:
        target = layout.distro_branch(opts.urls[0]) or DEFAULT_TARGET
        print "Implicit target: %s" % target
        opts.target = target
    del opts.distro
    return opts
Exemplo n.º 28
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.defaults["revision"] = None
    parser.add_option("-t", dest="target", default=None)
    parser.add_option("-l", action="callback", callback=list_targets)
    parser.add_option("-r", dest="revision", type="string", nargs=1)
    parser.add_option("-s",
                      dest="submithost",
                      type="string",
                      nargs=1,
                      default=None)
    parser.add_option("-i", dest="sid", type="string", nargs=1, default=None)
    parser.add_option("-a", dest="atonce", action="store_true", default=False)
    parser.add_option("--distro", dest="distro", type="string", default=None)
    parser.add_option("--define", action="append", default=[])
    opts, args = parser.parse_args()
    if not args:
        name, url, rev = get_submit_info(".")
        args = ["%s@%s" % (url, str(rev))]
        print("Submitting %s at revision %s" % (name, rev))
        print("URL: %s" % url)
    if opts.revision is not None:
        # backwards compatibility with the old -r usage
        if len(args) == 1:
            args[0] = args[0] + "@" + opts.revision
        else:
            raise Error("can't use -r REV with more than one package name")
    del opts.revision
    if len(args) == 2:
        # prevent from using the old <name> <rev> syntax
        try:
            rev = int(args[1])
        except ValueError:
            # ok, it is a package name, let it pass
            pass
        else:
            raise Error("the format <name> <revision> is deprecated, "\
                    "use <name>@<revision> instead")
    # expand group aliases
    expanded = []
    for nameurl in args:
        expanded.extend(expand_group(nameurl))
    if expanded != args:
        print("Submitting: %s" % " ".join(expanded))
        args = expanded
    # generate URLs for package names:
    opts.urls = [
        mirror.strip_username(
            layout.package_url(nameurl, distro=opts.distro, mirrored=False))
        for nameurl in args
    ]
    # find the revision if not specified:
    newurls = []
    for url in opts.urls:
        if not "@" in url:
            print("Fetching revision...")
            courl = layout.checkout_url(url)
            log = SVN().log(courl, limit=1)
            if not log:
                raise Error("can't find a revision for %s" % courl)
            ci = log[0]
            print("URL:", url)
            print("Commit:", end=' ')
            print("%d | %s" % (ci.revision, ci.author), end=' ')
            if ci.lines:
                line = " ".join(ci.lines).strip()
                if len(line) > 57:
                    line = line[:57] + "..."
                print("| %s" % line, end=' ')
            print()
            url = url + "@" + str(ci.revision)
        newurls.append(url)
    opts.urls[:] = newurls
    # choose a target if not specified:
    if opts.target is None and opts.distro is None:
        target = layout.distro_branch(opts.urls[0]) or DEFAULT_TARGET
        print("Implicit target: %s" % target)
        opts.target = target
    del opts.distro
    return opts
Exemplo n.º 29
0
def put_srpm(srpmfile, markrelease=False, striplog=True, branch=None,
        baseurl=None, baseold=None, logmsg=None, rename=True):
    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([pkgurl, "releases", version])
        releaseurl = "/".join([versionurl, srpm.release])
        currenturl = "/".join([pkgurl, "current"])
        currentdir = os.path.join(tmpdir, "current")
        #FIXME when pre-commit hook fails, there's no clear way to know
        # what happened
        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(currentdir)
            svn.mkdir(os.path.join(currentdir, "SPECS"))
            svn.mkdir(os.path.join(currentdir, "SOURCES"))
            #svn.commit(tmpdir,log="Created package structure.")
            version_exists = 1
        else:
            if svn.ls(releaseurl, noerror=1):
                raise Error, "release already exists"
            svn.checkout("/".join([pkgurl, "current"]), tmpdir)
            svn.mkdir(versionurl, noerror=1,
                      log="Created directory for version %s." % version)
            currentdir = tmpdir
         
        specsdir = os.path.join(currentdir, "SPECS")
        sourcesdir = os.path.join(currentdir, "SOURCES")

        unpackdir = tempfile.mktemp()
        os.mkdir(unpackdir)
        try:
            srpm.unpack(unpackdir)

            uspecsdir = os.path.join(unpackdir, "SPECS")
            usourcesdir = os.path.join(unpackdir, "SOURCES")
            
            uspecsentries = os.listdir(uspecsdir)
            usourcesentries = os.listdir(usourcesdir)
            specsentries = os.listdir(specsdir)
            sourcesentries = os.listdir(sourcesdir)

            # Remove old entries
            for entry in [x for x in specsentries
                             if x not in uspecsentries]:
                if entry == ".svn":
                    continue
                entrypath = os.path.join(specsdir, entry)
                os.unlink(entrypath)
                svn.remove(entrypath)
            for entry in [x for x in sourcesentries
                             if x not in usourcesentries]:
                if entry == ".svn":
                    continue
                entrypath = os.path.join(sourcesdir, entry)
                os.unlink(entrypath)
                svn.remove(entrypath)

            # Copy all files
            execcmd(["cp", "-rf", uspecsdir, currentdir])
            execcmd(["cp", "-rf", usourcesdir, currentdir])
            
            # Add new entries
            for entry in [x for x in uspecsentries
                             if x not in specsentries]:
                entrypath = os.path.join(specsdir, entry)
                svn.add(entrypath)
            for entry in [x for x in usourcesentries
                             if x not in sourcesentries]:
                entrypath = os.path.join(sourcesdir, entry)
                svn.add(entrypath)
        finally:
            if os.path.isdir(unpackdir):
                shutil.rmtree(unpackdir)

        specs = glob.glob(os.path.join(specsdir, "*.spec"))
        if not specs:
            raise Error, "no spec file found on %s" % specsdir
        if len(specs) > 1:
            raise Error, "more than one spec file found on %s" % specsdir
        specpath = specs[0]
        if rename:
            specfile = os.path.basename(specpath)
            specname = specfile[:-len(".spec")]
            if specname != srpm.name:
                newname = srpm.name + ".spec"
                newpath = os.path.join(specsdir, newname)
                sys.stderr.write("warning: renaming spec file to '%s' "
                        "(use -n to disable it)\n" % (newname))
                os.rename(specpath, newpath)
                try:
                    svn.remove(specpath)
                except Error:
                    # file not tracked
                    svn.revert(specpath)
                svn.add(newpath)
                specpath = newpath

        if striplog:
            specpath = specpath
            fspec = open(specpath)
            spec, chlog = log.split_spec_changelog(fspec)
            fspec.close()
            fspec = open(specpath, "w")
            fspec.writelines(spec)
            fspec.close()
            chlog.seek(0, os.SEEK_END)
            if chlog.tell() != 0:
                chlog.seek(0)
                #FIXME move it to layout.py
                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(pkgurl, pristine=True)
    svn.remove(pristineurl, noerror=1,
               log="Removing previous pristine/ directory.")
    currenturl = layout.checkout_url(pkgurl)
    svn.copy(currenturl, pristineurl,
             log="Copying release %s-%s to pristine/ directory." %
                 (version, srpm.release))
    if markrelease:
        svn.copy(currenturl, releaseurl,
                 log="Copying release %s-%s to releases/ directory." %
                     (version, srpm.release))