Change confname when already taken
If the confname of the file we want to add already exists (for a different abspath of course), we add a numeric extension to it. Same thing if the confname is the metafile name.master
parent
20566a3c89
commit
e6c4dcbdbc
|
@ -51,26 +51,6 @@ def run(args, persoconf, logger):
|
|||
if args.conf is None:
|
||||
exit()
|
||||
|
||||
# Check that the conf file we are saving exists
|
||||
if args.confname:
|
||||
confname = args.confname
|
||||
else:
|
||||
confname = args.conf
|
||||
|
||||
# We need to remove trailing '/' because 'os.path.basename("toto/")'
|
||||
# returns ''. And that's not cool.
|
||||
while confname[-1] == os.path.sep :
|
||||
confname = confname[:-1] # Remove trailing slashes
|
||||
|
||||
confname = os.path.basename(confname)
|
||||
|
||||
# Remove leading dots, so the name under which the conffile is saved is
|
||||
# not hidden.
|
||||
while confname[0] == ".":
|
||||
confname = confname[1:] # Remove leading dots
|
||||
|
||||
confpath = appdir + "/" + confname
|
||||
|
||||
# Load app META file
|
||||
try:
|
||||
appmeta = Metafile( json_path = os.path.join( appdir ,
|
||||
|
@ -107,6 +87,43 @@ def run(args, persoconf, logger):
|
|||
% (absconf, dstdic[absconf], args.app) )
|
||||
exit(1)
|
||||
|
||||
# Check that the conf file we are saving exists
|
||||
if args.confname:
|
||||
confname = args.confname
|
||||
else:
|
||||
confname = args.conf
|
||||
|
||||
# We need to remove trailing '/' because 'os.path.basename("toto/")'
|
||||
# returns ''. And that's not cool.
|
||||
while confname[-1] == os.path.sep :
|
||||
confname = confname[:-1] # Remove trailing slashes
|
||||
|
||||
confname = os.path.basename(confname)
|
||||
|
||||
# Remove leading dots, so the name under which the conffile is saved is
|
||||
# not hidden.
|
||||
while confname[0] == ".":
|
||||
confname = confname[1:] # Remove leading dots
|
||||
|
||||
|
||||
# Check the conf file name
|
||||
if ( confname == persoconf.metafile
|
||||
or confname in appmeta.files ):
|
||||
logger.info( "Confname '%s' is already taken: trying another one"
|
||||
% confname )
|
||||
|
||||
ending = 1
|
||||
|
||||
while ( confname + "." + str(ending) == persoconf.metafile
|
||||
or confname + "." + str(ending) in appmeta.files ):
|
||||
ending += 1
|
||||
|
||||
confname = confname + "." + str(ending)
|
||||
logger.info( "New confname is '%s'" % confname )
|
||||
|
||||
# Deduce the path from the conf file name
|
||||
confpath = appdir + "/" + confname
|
||||
|
||||
# Copy the file (or directory)
|
||||
if utils.copy_file_or_directory( logger ,
|
||||
path_dst=confpath ,
|
||||
|
|
Loading…
Reference in New Issue