[SCM] hydrogen-drumkits/master: get_orig_source.py: non-interactive mode + DEP5
umlaeute at users.alioth.debian.org
umlaeute at users.alioth.debian.org
Tue Sep 22 08:59:49 UTC 2015
The following commit has been merged in the master branch:
commit b1bb86fa7db694b695d5456b3a2368a541084148
Author: IOhannes m zmölnig <zmoelnig at umlautQ.umlaeute.mur.at>
Date: Tue Sep 22 10:42:00 2015 +0200
get_orig_source.py: non-interactive mode + DEP5
non-interactive: don't ask any questions and just re-download the files already approved
DEP5: generate a stub for DEP5-copyright file
diff --git a/debian/get-orig-source.py b/debian/get-orig-source.py
index 076f2a2..013708b 100755
--- a/debian/get-orig-source.py
+++ b/debian/get-orig-source.py
@@ -77,11 +77,8 @@ import tempfile
import xml.etree.ElementTree
URL = 'http://www.hydrogen-music.org/feeds/drumkit_list.php'
-WORKDIR='tmp/'
-PKGDIR=''
-
-DRUMKITDIR=os.path.join(PKGDIR, 'drumkits')
-
+#OUTFILE='hydrogen-drumkits.tar.gz'
+OUTFILE=None
### come compat foo
@@ -145,6 +142,9 @@ def stripPrefix(s, prefix, stripfix=None):
return s[len(stripfix):]
return s
+def makedir(path):
+ if not os.path.isdir(path):
+ os.makedirs(path)
def print_dict(obj):
for k in obj:
@@ -199,8 +199,7 @@ def download(url, outputfile=None):
if not outdir:
outdir=''
else:
- if not os.path.exists(outdir):
- os.makedirs(outdir)
+ makedir(outdir)
outputfile=os.path.join(outdir, outfile)
urllib.urlretrieve(url, outputfile)
@@ -216,8 +215,22 @@ def tarup(tarname, path, strippath):
tar.add(path, filter = filter)
return tarfilename
+
## core functions
+def write_dep5(path, pkgs):
+ if not path:
+ return
+ with open(path, 'w') as f:
+ for k in pkgs:
+ for p in pkgs[k]:
+ if not p.get('distribute'):
+ continue
+ f.write("\n")
+ f.write("Files: %s\n" % (os.path.join(k, p.get('filename'))))
+ f.write("Copyright: %s\n" % (p.get('author')))
+ f.write("License: %s\n" % p.get('licensed'))
+
def write_DrumkitInfo(path, dki, name=None):
if not name:
@@ -289,8 +302,7 @@ def guessFilenameFromURL(url):
return os.path.basename(url)
def downloadPkgs(pkgs, path):
- if not os.path.isdir(path):
- os.makedirs(path)
+ makedir(path)
count=0
for pkg in pkgs:
count=count+1
@@ -324,6 +336,7 @@ def pkg_drumkits(conf):
packd=get_packagedDrumkitsInfo(conf.pkgdir)
# list of available (online) drumkits
avail=[x for x in get_availableDrumkitsInfo(conf.uri)]
+ interactive=not conf.non_interactive
for pkg in avail:
# check if this has already been packaged
@@ -338,7 +351,7 @@ def pkg_drumkits(conf):
distribute=None
print("=================")
print_dict(pkg)
- if distribute is None:
+ if (distribute is None) and interactive:
while distribute is None:
try:
dis=raw_input("Add drumkit '%s' to package? [y/n/^D to skip] " % (pkg.get('name')))
@@ -352,45 +365,57 @@ def pkg_drumkits(conf):
print("Using prior decision about distribution: %s" % (distribute))
pkg['distribute']=distribute
if distribute:
- print("")
- lic=pkg.get('license')
- ## get a machine-readable license from the user
- license=pkg.get('licensed')
- while not license:
- try:
- license=raw_input("What's the machine-readable license ('%s')? " % (pkg.get('license')))
- except EOFError:
- if distribute:
- pass
- else:
- break
- if not license:
- license=lic
- pkg['licensed']=license
-
- ## make sure we have a sane output filename
- filename=pkg.get('filename')
- if not filename:
- url=pkg.get('url')
- filename=guessFilenameFromURL(url)
- #print("The drumkit will be downloaded from %s" % (url,))
- fname=raw_input("What should be the output filename ('%s')? " % (filename))
- if fname:
- filename=fname
- pkg['filename']=filename
+ if(interactive):
+ print("")
+ lic=pkg.get('license')
+ ## get a machine-readable license from the user
+ license=pkg.get('licensed')
+ while not license:
+ try:
+ license=raw_input("What's the machine-readable license ('%s')? " % (pkg.get('license')))
+ except EOFError:
+ if distribute:
+ pass
+ else:
+ break
+ if not license:
+ license=lic
+ pkg['licensed']=license
+
+ ## make sure we have a sane output filename
+ filename=pkg.get('filename')
+ if not filename:
+ url=pkg.get('url')
+ filename=guessFilenameFromURL(url)
+ #print("The drumkit will be downloaded from %s" % (url,))
+ fname=raw_input("What should be the output filename ('%s')? " % (filename))
+ if fname:
+ filename=fname
+ pkg['filename']=filename
print("")
pkgs = [x for x in avail if x.get('distribute')]
- downloadPkgs(pkgs, os.path.join(conf.workdir, 'drumkits'))
write_DrumkitInfo(conf.workdir, avail, 'drumkits')
+ download=True
+ if interactive:
+ try:
+ raw_input("Press [return] to proceed with downloading %d drumkits; ^D to skip\n")
+ except EOFError:
+ download=False
+ if download:
+ downloadPkgs(pkgs, os.path.join(conf.workdir, 'drumkits'))
+ return pkgs
def main(conf):
+ pkgs=dict()
outdir=conf.workdir
conf.workdir=os.path.join(conf.workdir, 'hydrogen-drumkits')
- pkg_drumkits(conf)
+ makedir(conf.workdir)
+ pkgs['drumkits']=pkg_drumkits(conf)
tarfile=tarup(conf.outfile, conf.workdir, outdir)
print("assembled package in %s" % tarfile)
+ write_dep5(conf.dep5, pkgs)
@@ -399,33 +424,45 @@ def parseCmdlineArgs():
parser.add_argument('-u', '--uri', type=str,
default=URL,
help="URI to read available packages from (DEFAULT: %(default)s)")
- parser.add_argument('-w', '--workdir', type=str,
- help="temporary directory to assemble tarball (DEFAULT: $TMPDIR)")
- parser.add_argument('-o', '--outfile', type=str,
- default="hydrogen-drumkits.tar.gz",
- help="output tarfile (DEFAULT: %(default)s)")
parser.add_argument('-p', '--pkgdir', type=str,
default=['.'],
action='append',
help="directory to read available packages from (DEFAULT: %(default)s)")
+ parser.add_argument('-o', '--outfile', type=str,
+ default=OUTFILE,
+ help="output tarfile (DEFAULT: %(default)s)")
+ parser.add_argument('--dep5', type=str,
+ help="output DEP5-copyright file (DEFAULT: None)")
+ parser.add_argument('-w', '--workdir', type=str,
+ help="temporary directory to assemble tarball (DEFAULT: $TMPDIR)")
+ parser.add_argument('-x', '--non-interactive', action='store_true',
+ help="don't ask interactive questions (re-create a tarball from all pre-approved items)"
+ )
args = parser.parse_args()
return args
if __name__ == '__main__':
+ if not OUTFILE:
+ from datetime import datetime as datetime
+ basefile=os.path.join('..', 'hydrogen-drumkit_'+datetime.today().strftime("%Y%m%d"))
+ suffix='.tar.gz'
+ OUTFILE=basefile+suffix
+ count=1
+ while(os.path.exists(OUTFILE)):
+ OUTFILE=("%s.%d%s" % (basefile, count, suffix))
+ count=count+1
args=parseCmdlineArgs()
if not args.uri:
args.uri = URL
if not args.pkgdir:
args.pkgdir=['.']
if args.workdir:
- if not os.path.exists(args.workdir):
- os.makedirs(args.workdir)
+ makedir(args.workdir)
wd=tempfile.mkdtemp(dir=args.workdir)
args.workdir=wd
print("args: %s" % (args,))
-
try:
main(args)
except BaseException:
--
hydrogen-drumkits packaging
More information about the pkg-multimedia-commits
mailing list