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 # 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,32 +388,43 @@ if args.command == "package":
pkgname = args.pkgname pkgname = args.pkgname
# TODO app == None => package all apps # TODO app == None => package all apps
appmetas = []
for app in args.apps :
# Load app META file # Load app META file
try: try:
appmeta = Metafile(json_path = "/".join([args.rootdir, args.apps[0], args.metafile])) 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 appmeta in appmetas:
for f in appmeta.files: for f in appmeta.files:
filename = args.rootdir +"/"+ appmeta.name +"/"+ f filename = args.rootdir +"/"+ appmeta.name +"/"+ f
filedest = appmeta.files[f]["dest"].replace("~/", "", 1) filedest = appmeta.files[f]["dest"]
# 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 # TODO save and restore owners and permissions
try: try: