Can package multiple apps

master
Lertsenem 2015-09-13 12:35:52 +02:00
parent 421354e9c9
commit 863f02d137
1 changed files with 33 additions and 22 deletions

View File

@ -180,7 +180,7 @@ parser_help = subparsers.add_parser("help", help="Print this help")
# Package
parser_package = subparsers.add_parser("package", help="Package a persoconf repository")
parser_package.add_argument( "apps", type=str, help="The apps to package ; defaults to all apps", nargs="*", default=[] )
parser_package.add_argument( "--pkgtype", "-t", type=str, help="The type of package to use", nargs="?", default="tar", choices = [ "tar" ] )
parser_package.add_argument( "--pkgtype", "-t", type=str, help="The type of package to use", nargs="?", default="tgz", choices = [ "tgz" ] )
parser_package.add_argument( "--pkgname", "-p", type=str, help="The name of the package to create", nargs="?", default="persoconf." + (time.strftime("%Y%m%d")) )
# Update
@ -388,39 +388,50 @@ if args.command == "package":
pkgname = args.pkgname
# TODO app == None => package all apps
# Load app META file
try:
appmeta = Metafile(json_path = "/".join([args.rootdir, args.apps[0], args.metafile]))
appmetas = []
for app in args.apps :
# Load app META file
try:
appmetas.append( Metafile(json_path = "/".join([args.rootdir, app, args.metafile])) )
except FileNotFoundError:
log.error("Metafile %s does not exist for app %s" % (args.metafile, args.apps[0]))
exit(1)
except FileNotFoundError:
log.warning("Metafile %s does not exist for app %s; ignoring" % (args.metafile, app))
continue
except MalformedMetafileError:
log.error("Malformed metafile %s in app %s" % (args.metafile, args.apps[0]) )
exit(1)
except MalformedMetafileError:
log.warning("Malformed metafile %s in app %s; ignoring" % (args.metafile, app) )
continue
# TODO check that the app exists
pkgname += "."
pkgname += appmeta.name
if args.pkgtype == "tar":
# Adds the app name if there is only one packaged
if len(appmetas) == 1:
pkgname += ("." + appmeta[0].name)
# Switch according to the pkgtype
if args.pkgtype == "tgz":
pkgname += ".tgz"
# Create a tar containing the files in the right place
pkg = tarfile.open(pkgname, "w:gz")
for f in appmeta.files:
filename = args.rootdir +"/"+ appmeta.name +"/"+ f
filedest = appmeta.files[f]["dest"].replace("~/", "", 1)
for appmeta in appmetas:
for f in appmeta.files:
filename = args.rootdir +"/"+ appmeta.name +"/"+ f
filedest = appmeta.files[f]["dest"]
# TODO save and restore owners and permissions
try:
pkg.add(filename, arcname=filedest)
log.info("Adding %s to package" % f)
except:
log.warning("Failed to add %s to tar package %s" % (f, pkgname))
# Remove possible 'home'. The final targz should be extracted
# at 'home.
if filedest[0] == '~' and filedest[1] == '/':
filedest = filedest[2:]
# TODO save and restore owners and permissions
try:
pkg.add(filename, arcname=filedest)
log.info("Adding %s to package" % f)
except:
log.warning("Failed to add %s to tar package %s" % (f, pkgname))
pkg.close()