aboutsummaryrefslogtreecommitdiffstats
path: root/RepSys/rpmutil.py
diff options
context:
space:
mode:
authorBogdano Arendartchuk <bogdano@mandriva.org>2008-02-08 00:43:26 +0000
committerBogdano Arendartchuk <bogdano@mandriva.org>2008-02-08 00:43:26 +0000
commit1e929f67375b699cdcac0b1557d115eed7035ae8 (patch)
tree63dd50265afd2b2385badb46476ff607ca5e10f4 /RepSys/rpmutil.py
parent5eb9f215eca3378738cddce68ce0977c6069357c (diff)
downloadmgarepo-1e929f67375b699cdcac0b1557d115eed7035ae8.tar
mgarepo-1e929f67375b699cdcac0b1557d115eed7035ae8.tar.gz
mgarepo-1e929f67375b699cdcac0b1557d115eed7035ae8.tar.bz2
mgarepo-1e929f67375b699cdcac0b1557d115eed7035ae8.tar.xz
mgarepo-1e929f67375b699cdcac0b1557d115eed7035ae8.zip
Added option -d to sync, to download the missing files
It also added a configuration option download-command, in the [global] section to define which command will be used to download. The default is wget.
Diffstat (limited to 'RepSys/rpmutil.py')
-rw-r--r--RepSys/rpmutil.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/RepSys/rpmutil.py b/RepSys/rpmutil.py
index 6fae669..3bb1b50 100644
--- a/RepSys/rpmutil.py
+++ b/RepSys/rpmutil.py
@@ -9,6 +9,7 @@ from RepSys.command import default_parent
import rpm
import tempfile
import shutil
+import string
import glob
import sys
import os
@@ -409,7 +410,7 @@ def _getpkgtopdir(basedir=None):
topdir = ""
return topdir
-def sync(dryrun=False):
+def sync(dryrun=False, download=False):
svn = SVN()
topdir = _getpkgtopdir()
# run svn info because svn st does not complain when topdir is not an
@@ -429,18 +430,34 @@ def sync(dryrun=False):
spec = rpm.TransactionSet().parseSpec(specpath)
except rpm.error, e:
raise Error, "could not load spec file: %s" % e
- sources = [os.path.basename(name)
- for name, no, flags in spec.sources()]
- sourcesst = dict((os.path.basename(path), st)
+ sources = dict((os.path.basename(name), name)
+ for name, no, flags in spec.sources())
+ sourcesst = dict((os.path.basename(path), (path, st))
for st, path in svn.status(sourcesdir, noignore=True))
toadd = []
- for source in sources:
+ for source, url in sources.iteritems():
sourcepath = os.path.join(sourcesdir, source)
- if sourcesst.get(source):
+ pst = sourcesst.get(source)
+ if pst:
if os.path.isfile(sourcepath):
toadd.append(sourcepath)
else:
- sys.stderr.write("warning: %s not found\n" % sourcepath)
+ sys.stderr.write("warning: %s not found, skipping\n" % sourcepath)
+ elif download and not os.path.isfile(sourcepath):
+ print "%s not found, downloading from %s" % (sourcepath, url)
+ fmt = config.get("global", "download-command",
+ "wget -c -O '$dest' $url")
+ context = {"dest": sourcepath, "url": url}
+ try:
+ cmd = string.Template(fmt).substitute(context)
+ except KeyError, e:
+ raise Error, "invalid variable %r in download-command "\
+ "configuration option" % e
+ execcmd(cmd, show=True)
+ if os.path.isfile(sourcepath):
+ toadd.append(sourcepath)
+ else:
+ raise Error, "file not found: %s" % sourcepath
# rm entries not found in sources and still in svn
found = os.listdir(sourcesdir)
toremove = []