Adding default to 'update': all apps/all files
parent
f158f3f371
commit
e36ee84d07
|
@ -237,6 +237,7 @@ parser_update = subparsers.add_parser( "update",
|
||||||
|
|
||||||
parser_update.add_argument( "app",
|
parser_update.add_argument( "app",
|
||||||
type=str,
|
type=str,
|
||||||
|
nargs="?",
|
||||||
help="The app to update" )
|
help="The app to update" )
|
||||||
|
|
||||||
parser_update.add_argument( "files",
|
parser_update.add_argument( "files",
|
||||||
|
@ -427,56 +428,105 @@ if args.command == "add":
|
||||||
########################################
|
########################################
|
||||||
if args.command == "update":
|
if args.command == "update":
|
||||||
|
|
||||||
# TODO app == None => update all apps
|
# app == None => update all apps
|
||||||
# Load app META file
|
apps_to_update = {}
|
||||||
try:
|
if args.app is None:
|
||||||
appmeta = Metafile(json_path = "/".join([persoconf.path, args.app, persoconf.metafile]))
|
apps_to_update = persoconf.list_apps(logger=log)
|
||||||
|
|
||||||
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) )
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
# TODO check that the app exists
|
|
||||||
|
|
||||||
# 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()
|
|
||||||
|
|
||||||
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
|
|
||||||
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 they were no 'file' args, it means we need to update all files in the app
|
|
||||||
else:
|
else:
|
||||||
for f in appmeta.files:
|
try:
|
||||||
if copy_file_or_directory(log, path_dst='/'.join([persoconf.path, args.app, f]), path_src=appmeta.files[f]["dest"]):
|
appmeta = Metafile( json_path = persoconf.path +"/"+
|
||||||
log.info("Updated %s from %s" % (f, appmeta.files[f]["dest"]))
|
args.app +"/"+
|
||||||
else:
|
persoconf.metafile )
|
||||||
log.warning("Failed to update %s from %s ; ignoring" % (f, appmeta.files[f]["dest"]))
|
|
||||||
|
apps_to_update[appmeta.name] = appmeta
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
log.error( "Metafile %s does not exist for app %s"
|
||||||
|
% (persoconf.metafile, args.app) )
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
except MalformedMetafileError:
|
||||||
|
log.error( "Malformed metafile %s in app %s"
|
||||||
|
% (persoconf.metafile, args.app) )
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
for app in apps_to_update:
|
||||||
|
|
||||||
|
if args.files != []:
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
# 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 = persoconf.path
|
||||||
|
+"/"+ 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) )
|
||||||
|
|
||||||
|
# 3) Otherwise, no idea what it is
|
||||||
|
else:
|
||||||
|
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
|
# PACKAGE COMMAND
|
||||||
########################################
|
########################################
|
||||||
|
|
Loading…
Reference in New Issue