本文整理汇总了Python中RepSys.svn.SVN类的典型用法代码示例。如果您正苦于以下问题:Python SVN类的具体用法?Python SVN怎么用?Python SVN使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SVN类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_old_log
def get_old_log(pkgdirurl):
chlog = StringIO()
oldurl = config.get("log", "oldurl")
if oldurl:
svn = SVN()
tmpdir = tempfile.mktemp()
try:
pkgname = layout.package_name(pkgdirurl)
pkgoldurl = os.path.join(oldurl, pkgname)
try:
# we're using HEAD here because fixes in misc/ (oldurl) may
# be newer than packages' last changed revision.
svn.export(pkgoldurl, tmpdir)
except Error:
pass
else:
logfile = os.path.join(tmpdir, "log")
if os.path.isfile(logfile):
file = open(logfile)
chlog.write("\n") # TODO needed?
log = file.read()
log = escape_macros(log)
chlog.write(log)
file.close()
finally:
if os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
chlog.seek(0)
return chlog
示例2: commit
def commit(target=".", message=None, logfile=None):
svn = SVN()
status = svn.status(target, quiet=True)
if not status:
print "nothing to commit"
return
info = svn.info2(target)
url = info.get("URL")
if url is None:
raise Error, "working copy URL not provided by svn info"
mirrored = mirror.using_on(url)
if mirrored:
newurl = mirror.switchto_parent(svn, url, target)
print "relocated to", newurl
# we can't use the svn object here because svn --non-interactive option
# hides VISUAL
opts = []
if message is not None:
opts.append("-m \"%s\"" % message)
if logfile is not None:
opts.append("-F \"%s\"" % logfile)
mopts = " ".join(opts)
os.system("svn ci %s %s" % (mopts, target))
if mirrored:
print "use \"repsys switch\" in order to switch back to mirror "\
"later"
示例3: check_changed
def check_changed(pkgdirurl, all=0, show=0, verbose=0):
svn = SVN()
if all:
baseurl = pkgdirurl
packages = []
if verbose:
print "Getting list of packages...",
sys.stdout.flush()
packages = [x[:-1] for x in svn.ls(baseurl)]
if verbose:
print "done"
if not packages:
raise Error, "couldn't get list of packages"
else:
baseurl, basename = os.path.split(pkgdirurl)
packages = [basename]
clean = []
changed = []
nopristine = []
nocurrent = []
for package in packages:
pkgdirurl = os.path.join(baseurl, package)
current = layout.checkout_url(pkgdirurl)
pristine = layout.checkout_url(pkgdirurl, pristine=True)
if verbose:
print "Checking package %s..." % package,
sys.stdout.flush()
if not svn.ls(current, noerror=1):
if verbose:
print "NO CURRENT"
nocurrent.append(package)
elif not svn.ls(pristine, noerror=1):
if verbose:
print "NO PRISTINE"
nopristine.append(package)
else:
diff = svn.diff(pristine, current)
if diff:
changed.append(package)
if verbose:
print "CHANGED"
if show:
print diff
else:
if verbose:
print "clean"
clean.append(package)
if verbose:
if not packages:
print "No packages found!"
elif all:
print "Total clean packages: %s" % len(clean)
print "Total CHANGED packages: %d" % len(changed)
print "Total NO CURRENT packages: %s" % len(nocurrent)
print "Total NO PRISTINE packages: %s" % len(nopristine)
return {"clean": clean,
"changed": changed,
"nocurrent": nocurrent,
"nopristine": nopristine}
示例4: get_submit_info
def get_submit_info(path):
path = os.path.abspath(path)
# First, look for SPECS and SOURCES directories.
found = False
while path != "/":
if os.path.isdir(path):
specsdir = os.path.join(path, "SPECS")
sourcesdir = os.path.join(path, "SOURCES")
if os.path.isdir(specsdir) and os.path.isdir(sourcesdir):
found = True
break
path = os.path.dirname(path)
if not found:
raise Error, "SPECS and/or SOURCES directories not found"
# Then, check if this is really a subversion directory.
if not os.path.isdir(os.path.join(path, ".svn")):
raise Error, "subversion directory not found"
svn = SVN()
# Now, extract the package name.
info = svn.info2(path)
url = info.get("URL")
if url is None:
raise Error, "missing URL from svn info %s" % path
toks = url.split("/")
if len(toks) < 2 or toks[-1] != "current":
raise Error, "unexpected URL received from 'svn info'"
name = toks[-2]
url = "/".join(toks[:-1])
# Finally, guess revision.
max = -1
files = []
files.extend(glob.glob("%s/*" % specsdir))
files.extend(glob.glob("%s/*" % sourcesdir))
for file in files:
try:
info = svn.info2(file)
except Error:
# possibly not tracked
continue
if info is None:
continue
rawrev = info.get("Last Changed Rev")
if rawrev:
rev = int(rawrev)
if rev > max:
max = rev
if max == -1:
raise Error, "revision tag not found in 'svn info' output"
if mirror.using_on(url):
url = mirror.switchto_parent_url(url)
return name, url, max
示例5: switch
def switch(mirrorurl=None):
svn = SVN()
topdir = _getpkgtopdir()
info = svn.info2(topdir)
wcurl = info.get("URL")
if wcurl is None:
raise Error, "working copy URL not provided by svn info"
newurl = mirror.autoswitch(svn, topdir, wcurl, mirrorurl)
print "switched to", newurl
示例6: rpmlog
def rpmlog(pkgdirurl, revision, size, template, oldlog, usespec, sort):
another = None
if usespec:
svn = SVN()
specurl = layout.package_spec_url(pkgdirurl)
rawspec = svn.cat(specurl, rev=revision)
spec, another = split_spec_changelog(StringIO(rawspec))
newlog = get_changelog(
pkgdirurl, another=another, rev=revision, size=size, sort=sort, template=template, oldlog=oldlog
)
sys.stdout.writelines(newlog)
示例7: checkout
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)
示例8: rev_touched_url
def rev_touched_url(url, rev):
svn = SVN()
info = svn.info2(url)
if info is None:
raise Error, "can't fetch svn info about the URL: %s" % url
root = info["Repository Root"]
urlpath = url[len(root):]
touched = False
entries = svn.log(root, start=rev, limit=1)
entry = entries[0]
for change in entry.changed:
path = change.get("path")
if path and path.startswith(urlpath):
touched = True
return touched
示例9: get_spec
def get_spec(pkgdirurl, targetdir=".", submit=False):
svn = SVN()
tmpdir = tempfile.mktemp()
try:
geturl = layout.checkout_url(pkgdirurl, append_path="SPECS")
mirror.info(geturl)
svn.export("'%s'" % geturl, tmpdir)
speclist = glob.glob(os.path.join(tmpdir, "*.spec"))
if not speclist:
raise Error, "no spec files found"
spec = speclist[0]
shutil.copy(spec, targetdir)
finally:
if os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
示例10: get_url_revision
def get_url_revision(url, retrieve=True):
"""Get the revision from a given URL
If the URL contains an explicit revision number ([email protected]), just use it
without even checking if the revision really exists.
The parameter retrieve defines whether it must ask the SVN server for
the revision number or not when it is not found in the URL.
"""
url, rev = split_url_revision(url)
if rev is None and retrieve:
# if no revspec was found, ask the server
svn = SVN()
rev = svn.revision(url)
return rev
示例11: getrelease
def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
"""Tries to obtain the version-release of the package for a
yet-not-markrelease revision of the package.
Is here where things should be changed if "automatic release increasing"
will be used.
"""
from RepSys.rpmutil import rpm_macros_defs
svn = SVN()
pkgcurrenturl = os.path.join(pkgdirurl, "current")
specurl = os.path.join(pkgcurrenturl, "SPECS")
if exported is None:
tmpdir = tempfile.mktemp()
svn.export(specurl, tmpdir, rev=rev)
else:
tmpdir = os.path.join(exported, "SPECS")
try:
found = glob.glob(os.path.join(tmpdir, "*.spec"))
if not found:
raise Error, "no .spec file found inside %s" % specurl
specpath = found[0]
options = rpm_macros_defs(macros)
command = (("rpm -q --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' "
"--specfile %s %s") %
(specpath, options))
pipe = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
pipe.wait()
output = pipe.stdout.read()
error = pipe.stderr.read()
if pipe.returncode != 0:
raise Error, "Error in command %s: %s" % (command, error)
releases = output.split()
try:
epoch, vr = releases[0].split(":", 1)
version, release = vr.split("-", 1)
except ValueError:
raise Error, "Invalid command output: %s: %s" % \
(command, output)
#XXX check if this is the right way:
if epoch == "(none)":
ev = version
else:
ev = epoch + ":" + version
return ev, release
finally:
if exported is None and os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
示例12: getrelease
def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
"""Tries to obtain the version-release of the package for a
yet-not-markrelease revision of the package.
Is here where things should be changed if "automatic release increasing"
will be used.
"""
svn = SVN()
pkgcurrenturl = os.path.join(pkgdirurl, "current")
specurl = os.path.join(pkgcurrenturl, "SPECS")
if exported is None:
tmpdir = tempfile.mktemp()
svn.export(specurl, tmpdir, rev=rev)
else:
tmpdir = os.path.join(exported, "SPECS")
try:
found = glob.glob(os.path.join(tmpdir, "*.spec"))
if not found:
raise Error, "no .spec file found inside %s" % specurl
specpath = found[0]
args = ["rpm", "-q", "--qf", "%{EPOCH}:%{VERSION}-%{RELEASE}\n",
"--specfile", specpath]
for pair in macros:
args.extend(("--define", "%s %s" % pair))
proc = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if proc.wait() != 0:
raise CommandError(args, proc.returncode, proc.stderr.read())
output = proc.stdout.read()
releases = output.split()
try:
epoch, vr = releases[0].split(":", 1)
version, release = vr.split("-", 1)
except ValueError:
raise Error, "Invalid command output: %s: %s" % \
(args, output)
#XXX check if this is the right way:
if epoch == "(none)":
ev = version
else:
ev = epoch + ":" + version
return ev, release
finally:
if exported is None and os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
示例13: patch_spec
def patch_spec(pkgdirurl, patchfile, log=""):
#FIXME use get_spec
svn = SVN()
tmpdir = tempfile.mktemp()
try:
geturl = layout.checkout_url(pkgdirurl, append_path="SPECS")
svn.checkout(geturl, tmpdir)
speclist = glob.glob(os.path.join(tmpdir, "*.spec"))
if not speclist:
raise Error, "no spec files found"
spec = speclist[0]
status, output = execcmd(["patch", spec, patchfile])
if status != 0:
raise Error, "can't apply patch:\n%s\n" % output
else:
svn.commit(tmpdir, log="")
finally:
if os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
示例14: sync
def sync(dryrun=False, download=False):
svn = SVN()
topdir = _getpkgtopdir()
# run svn info because svn st does not complain when topdir is not an
# working copy
svn.info(topdir or ".")
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:
rpm.addMacro("_topdir", os.path.abspath(topdir))
spec = rpm.TransactionSet().parseSpec(specpath)
except rpm.error, e:
raise Error, "could not load spec file: %s" % e
示例15: get_srpm
def get_srpm(pkgdirurl,
mode = "current",
targetdirs = None,
version = None,
release = None,
revision = None,
packager = "",
revname = 0,
svnlog = 0,
scripts = [],
submit = False,
template = None,
distro = None,
macros = [],
verbose = 0,
strict = False):
svn = SVN()
tmpdir = tempfile.mktemp()
topdir = "_topdir %s" % tmpdir
builddir = "_builddir %s/%s" % (tmpdir, "BUILD")
rpmdir = "_rpmdir %s/%s" % (tmpdir, "RPMS")
sourcedir = "_sourcedir %s/%s" % (tmpdir, "SOURCES")
specdir = "_specdir %s/%s" % (tmpdir, "SPECS")
srcrpmdir = "_srcrpmdir %s/%s" % (tmpdir, "SRPMS")
patchdir = "_patchdir %s/%s" % (tmpdir, "SOURCES")
temppath = "_tmppath %s" % (tmpdir)
rpmdefs = [("--define", expr) for expr in (topdir, builddir, rpmdir,
sourcedir, specdir, srcrpmdir, patchdir, temppath)]
try:
if mode == "version":
geturl = layout.checkout_url(pkgdirurl, version=version,
release=release)
elif mode == "pristine":
geturl = layout.checkout_url(pkgdirurl, pristine=True)
elif mode == "current" or mode == "revision":
#FIXME we should handle revisions specified using @REV
geturl = layout.checkout_url(pkgdirurl)
else:
raise Error, "unsupported get_srpm mode: %s" % mode
strict = strict or config.getbool("submit", "strict-revision", False)
if strict and not rev_touched_url(geturl, revision):
#FIXME would be nice to have the revision number even when
# revision is None
raise Error, "the revision %s does not change anything "\
"inside %s" % (revision or "HEAD", geturl)
mirror.info(geturl)
svn.export(geturl, tmpdir, rev=revision)
srpmsdir = os.path.join(tmpdir, "SRPMS")
os.mkdir(srpmsdir)
specsdir = os.path.join(tmpdir, "SPECS")
speclist = glob.glob(os.path.join(specsdir, "*.spec"))
if config.getbool("srpm", "run-prep", False):
makefile = os.path.join(tmpdir, "Makefile")
if os.path.exists(makefile):
execcmd(("make", "-C", tmpdir, "srpm-prep"))
if not speclist:
raise Error, "no spec files found"
spec = speclist[0]
if svnlog:
submit = not not revision
log.specfile_svn2rpm(pkgdirurl, spec, revision, submit=submit,
template=template, macros=macros, exported=tmpdir)
for script in scripts:
#FIXME revision can be "None"
status, output = execcmd(script, tmpdir, spec, str(revision),
noerror=1)
if status != 0:
raise Error, "script %s failed" % script
if packager:
packager = " --define 'packager %s'" % packager
if distro:
cmpdistro = distro.lower()
for target in cgiutil.get_targets():
if target.name.lower() == cmpdistro:
macros.extend(target.macros)
break
else:
raise Error, "no such submit target in configuration: %s" % (distro)
sourcecmd = config.get("helper", "rpmbuild", "rpmbuild")
args = [sourcecmd, "-bs", "--nodeps"]
for pair in rpmdefs:
args.extend(pair)
for pair in macros:
args.extend(("--define", "%s %s" % pair))
args.append(spec)
try:
execcmd(args)
except CommandError, e:
if config.getbool("global", "verbose"):
cmdline = e.cmdline + "\n"
else:
cmdline = ""
raise Error, ("error while creating the source RPM "
"(with %s):\n%s%s" % (sourcecmd, cmdline, e.output))
# copy the generated SRPMs to their target locations
targetsrpms = []
#.........这里部分代码省略.........