diff --git a/commands/add.py b/commands/add.py index 249a82e..64cc63e 100644 --- a/commands/add.py +++ b/commands/add.py @@ -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 ,