Can package multiple apps
parent
421354e9c9
commit
863f02d137
|
@ -180,7 +180,7 @@ parser_help = subparsers.add_parser("help", help="Print this help")
|
||||||
# Package
|
# Package
|
||||||
parser_package = subparsers.add_parser("package", help="Package a persoconf repository")
|
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( "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")) )
|
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
|
# Update
|
||||||
|
@ -388,39 +388,50 @@ if args.command == "package":
|
||||||
pkgname = args.pkgname
|
pkgname = args.pkgname
|
||||||
|
|
||||||
# TODO app == None => package all apps
|
# TODO app == None => package all apps
|
||||||
# Load app META file
|
appmetas = []
|
||||||
try:
|
for app in args.apps :
|
||||||
appmeta = Metafile(json_path = "/".join([args.rootdir, args.apps[0], args.metafile]))
|
# Load app META file
|
||||||
|
try:
|
||||||
|
appmetas.append( Metafile(json_path = "/".join([args.rootdir, app, args.metafile])) )
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
log.error("Metafile %s does not exist for app %s" % (args.metafile, args.apps[0]))
|
log.warning("Metafile %s does not exist for app %s; ignoring" % (args.metafile, app))
|
||||||
exit(1)
|
continue
|
||||||
|
|
||||||
except MalformedMetafileError:
|
except MalformedMetafileError:
|
||||||
log.error("Malformed metafile %s in app %s" % (args.metafile, args.apps[0]) )
|
log.warning("Malformed metafile %s in app %s; ignoring" % (args.metafile, app) )
|
||||||
exit(1)
|
continue
|
||||||
|
|
||||||
# TODO check that the app exists
|
# 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"
|
pkgname += ".tgz"
|
||||||
|
|
||||||
# Create a tar containing the files in the right place
|
# Create a tar containing the files in the right place
|
||||||
pkg = tarfile.open(pkgname, "w:gz")
|
pkg = tarfile.open(pkgname, "w:gz")
|
||||||
|
|
||||||
for f in appmeta.files:
|
for appmeta in appmetas:
|
||||||
filename = args.rootdir +"/"+ appmeta.name +"/"+ f
|
for f in appmeta.files:
|
||||||
filedest = appmeta.files[f]["dest"].replace("~/", "", 1)
|
filename = args.rootdir +"/"+ appmeta.name +"/"+ f
|
||||||
|
filedest = appmeta.files[f]["dest"]
|
||||||
|
|
||||||
# TODO save and restore owners and permissions
|
# Remove possible 'home'. The final targz should be extracted
|
||||||
try:
|
# at 'home.
|
||||||
pkg.add(filename, arcname=filedest)
|
if filedest[0] == '~' and filedest[1] == '/':
|
||||||
log.info("Adding %s to package" % f)
|
filedest = filedest[2:]
|
||||||
except:
|
|
||||||
log.warning("Failed to add %s to tar package %s" % (f, pkgname))
|
# 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()
|
pkg.close()
|
||||||
|
|
Loading…
Reference in New Issue