Adding default to 'update': all apps/all files

master
Lertsenem 2015-09-16 17:34:35 +02:00
parent f158f3f371
commit e36ee84d07
1 changed files with 98 additions and 48 deletions

View File

@ -237,6 +237,7 @@ parser_update = subparsers.add_parser( "update",
parser_update.add_argument( "app",
type=str,
nargs="?",
help="The app to update" )
parser_update.add_argument( "files",
@ -427,56 +428,105 @@ if args.command == "add":
########################################
if args.command == "update":
# TODO app == None => update all apps
# Load app META file
# app == None => update all apps
apps_to_update = {}
if args.app is None:
apps_to_update = persoconf.list_apps(logger=log)
else:
try:
appmeta = Metafile(json_path = "/".join([persoconf.path, args.app, persoconf.metafile]))
appmeta = Metafile( json_path = persoconf.path +"/"+
args.app +"/"+
persoconf.metafile )
apps_to_update[appmeta.name] = appmeta
except FileNotFoundError:
log.info("Metafile %s does not exist for app %s" % (persoconf.metafile, args.app))
appmeta = Metafile( name=args.app )
appmeta.json_path = "/".join( [persoconf.path, args.app, persoconf.metafile] )
except MalformedMetafileError:
log.error("Malformed metafile %s in app %s" % (persoconf.metafile, args.app) )
log.error( "Metafile %s does not exist for app %s"
% (persoconf.metafile, args.app) )
exit(1)
# TODO check that the app exists
except MalformedMetafileError:
log.error( "Malformed metafile %s in app %s"
% (persoconf.metafile, args.app) )
exit(1)
for app in apps_to_update:
# The filenames can be confnames or real files names. For each we'll assume
# first that it's a confname, then that it's a file name if that fails.
if args.files != []:
dstdic = appmeta.get_files_dst2src()
dstdic = apps_to_update[app].get_files_dst2src()
# The filenames can be confnames or real files names. For each
# we'll assume first that it's a confname, then that it's a file
# name if that fails.
for f in args.files:
# It's probably a confname
if f in appmeta.files:
if copy_file_or_directory(log, path_dst='/'.join([persoconf.path, args.app, f]), path_src=appmeta.files[f]["dest"]):
log.info("Updated %s from %s" % (f, appmeta.files[f]["dest"]))
else:
log.warning("Failed to update %s from %s ; ignoring" % (f, appmeta.files[f]["dest"]))
# If not, it must be a real filename
# 1) It's probably a confname
if f in apps_to_update[app].files:
if copy_file_or_directory(
log ,
path_dst = persoconf.path
+"/"+ app
+"/"+ f ,
path_src = apps_to_update[app].files[f]["dest"]
):
log.info( "Updated %s from %s"
% (f, apps_to_update[app].files[f]["dest"]) )
else:
log.warning(
"Failed to update %s from %s ; ignoring"
% ( f, apps_to_update[app].files[f]["dest"])
)
# 2) If not, it must be a real filename
else:
absf = contractuser(os.path.abspath(os.path.expanduser(f)))
if absf in dstdic:
if copy_file_or_directory(log, path_dst='/'.join([persoconf.path, args.app, dstdic[absf]]), path_src=absf):
log.info("Updated %s from %s" % (dstdic[absf], absf))
else:
log.warning("Failed to update %s from %s ; ignoring" % (dstdic[absf], absf))
# Otherwise, it's nothing.
else:
log.warning("Cannot find file %s in app data; ignoring it")
if copy_file_or_directory(
log ,
path_dst = persoconf.path
+"/"+ app
+"/"+ dstdic[absf] ,
path_src = absf
):
log.info( "Updated %s from %s"
% (dstdic[absf], absf) )
# If they were no 'file' args, it means we need to update all files in the app
else:
for f in appmeta.files:
if copy_file_or_directory(log, path_dst='/'.join([persoconf.path, args.app, f]), path_src=appmeta.files[f]["dest"]):
log.info("Updated %s from %s" % (f, appmeta.files[f]["dest"]))
log.warning( "Failed to update %s from %s ; " \
"ignoring"
% (dstdic[absf], absf) )
# 3) Otherwise, no idea what it is
else:
log.warning("Failed to update %s from %s ; ignoring" % (f, appmeta.files[f]["dest"]))
log.warning( "Cannot find file %s in app data; " \
"ignoring it"
% f )
# If they were no 'file' args, it means we need to update all files in
# the app
else:
for f in apps_to_update[app].files:
if copy_file_or_directory(
log ,
path_dst = persoconf.path
+"/"+ app
+"/"+ f ,
path_src = apps_to_update[app].files[f]["dest"]
):
log.info( "Updated %s from %s"
% (f, apps_to_update[app].files[f]["dest"]) )
else:
log.warning( "Failed to update %s from %s ; ignoring"
% (f, apps_to_update[app].files[f]["dest"]) )
# PACKAGE COMMAND
########################################