Readability revamp
parent
67f3d16b06
commit
f158f3f371
|
@ -64,11 +64,14 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
logger.error("Cannot replace backup %s because of permissions" % (dst + ".bak"))
|
logger.error("Cannot replace backup %s because of permissions"
|
||||||
|
% (dst + ".bak"))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
logger.error("%s has been created, you need to chose manually to keep it or to use the backup %s" % (dst, dst + ".bak"))
|
logger.error("%s has been created, you need to chose " \
|
||||||
|
"manually to keep it or to use the backup %s"
|
||||||
|
% (dst, dst + ".bak"))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -83,7 +86,8 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True):
|
||||||
logger.info("No file %s exists yet" % dst)
|
logger.info("No file %s exists yet" % dst)
|
||||||
|
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
logger.error("Unable to write %s, please check permissions" % (dst + ".bak"))
|
logger.error("Unable to write %s, please check permissions"
|
||||||
|
% (dst + ".bak"))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
|
@ -149,9 +153,12 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True):
|
||||||
shutil.rmtree(dst + ".bak")
|
shutil.rmtree(dst + ".bak")
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.warning("Backup file %s seems to be already gone" % (dst + ".bak"))
|
logger.warning("Backup file %s seems to be already gone"
|
||||||
|
% (dst + ".bak"))
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
logger.warning("Cannot remove backup dir %s, you will have to do it manually" % (dst + ".bak"))
|
logger.warning("Cannot remove backup dir %s, you will have to " \
|
||||||
|
"do it manually"
|
||||||
|
% (dst + ".bak"))
|
||||||
|
|
||||||
# If not, try it as a file
|
# If not, try it as a file
|
||||||
except NotADirectoryError:
|
except NotADirectoryError:
|
||||||
|
@ -160,7 +167,9 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True):
|
||||||
os.remove(dst + ".bak")
|
os.remove(dst + ".bak")
|
||||||
|
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
logger.warning("Cannot remove backup file %s, you will have to do it manually" % (dst + ".bak"))
|
logger.warning("Cannot remove backup file %s, you will have " \
|
||||||
|
"to do it manually"
|
||||||
|
% (dst + ".bak"))
|
||||||
|
|
||||||
|
|
||||||
# The End.
|
# The End.
|
||||||
|
@ -172,12 +181,23 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True):
|
||||||
########################################
|
########################################
|
||||||
# Argument parsing using argparse
|
# Argument parsing using argparse
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument( "--rootdir", type=str, help="The persoconf directory to use", default="~/.config/persoconf/" )
|
|
||||||
parser.add_argument( "--metafile", type=str, help="The name of the metadata files", default="META" )
|
parser.add_argument( "--rootdir",
|
||||||
parser.add_argument( '--verbose', "-v", help='Spout out more logs', action="store_true")
|
type=str,
|
||||||
|
default="~/.config/persoconf/",
|
||||||
|
help="The persoconf directory to use" )
|
||||||
|
|
||||||
|
parser.add_argument( "--metafile",
|
||||||
|
type=str,
|
||||||
|
default="META",
|
||||||
|
help="The name of the metadata files" )
|
||||||
|
|
||||||
|
parser.add_argument( "--verbose", "-v",
|
||||||
|
action="store_true",
|
||||||
|
help="Spout out more logs" )
|
||||||
|
|
||||||
|
|
||||||
subparsers = parser.add_subparsers( dest="command", title="commands") #, description="Valid commands" )
|
subparsers = parser.add_subparsers( dest="command", title="commands")
|
||||||
|
|
||||||
# Help
|
# Help
|
||||||
parser_help = subparsers.add_parser("help", help="Print this help")
|
parser_help = subparsers.add_parser("help", help="Print this help")
|
||||||
|
@ -186,23 +206,69 @@ parser_help = subparsers.add_parser("help", help="Print this help")
|
||||||
parser_list = subparsers.add_parser("list", help="List backuped apps")
|
parser_list = subparsers.add_parser("list", help="List backuped apps")
|
||||||
|
|
||||||
# Package
|
# Package
|
||||||
parser_package = subparsers.add_parser("package", help="Package a persoconf repository")
|
parser_package = subparsers.add_parser( "package",
|
||||||
parser_package.add_argument( "apps", type=str, help="The apps to package ; defaults to all apps", nargs="*", default=[] )
|
help="Package a persoconf repository" )
|
||||||
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( "apps",
|
||||||
|
type=str,
|
||||||
|
nargs="*",
|
||||||
|
default=[],
|
||||||
|
help="The apps to package ; defaults to all " \
|
||||||
|
"apps" )
|
||||||
|
|
||||||
|
parser_package.add_argument( "--pkgtype", "-t",
|
||||||
|
type=str,
|
||||||
|
nargs="?",
|
||||||
|
default="tgz",
|
||||||
|
choices = [ "tgz" ],
|
||||||
|
help="The type of package to use" )
|
||||||
|
|
||||||
|
parser_package.add_argument( "--pkgname", "-p",
|
||||||
|
type=str,
|
||||||
|
nargs="?",
|
||||||
|
default="persoconf." + (time.strftime("%Y%m%d")),
|
||||||
|
help="The name of the package to create" )
|
||||||
|
|
||||||
# Update
|
# Update
|
||||||
parser_update = subparsers.add_parser("update", help="Backup an app configuration in the persoconf directory with the configuration in use now")
|
parser_update = subparsers.add_parser( "update",
|
||||||
parser_update.add_argument( 'app', help='The app to update', type=str )
|
help="Backup an app configuration in " \
|
||||||
parser_update.add_argument( 'files', help='The files to update ; default to all added files', type=str, nargs="*", default=[])
|
"the persoconf directory with " \
|
||||||
|
"the configuration in use now" )
|
||||||
|
|
||||||
|
parser_update.add_argument( "app",
|
||||||
|
type=str,
|
||||||
|
help="The app to update" )
|
||||||
|
|
||||||
|
parser_update.add_argument( "files",
|
||||||
|
type=str,
|
||||||
|
nargs="*",
|
||||||
|
default=[],
|
||||||
|
help="The files to update ; default to all " \
|
||||||
|
"added files" )
|
||||||
|
|
||||||
# Add
|
# Add
|
||||||
parser_add = subparsers.add_parser("add", help="Add an app to the persoconf directory, or add a config file to an existing app")
|
parser_add = subparsers.add_parser( "add",
|
||||||
parser_add.add_argument( 'app', help="The app to add, or the app to add a conf file to", type=str)
|
help="Add an app to the persoconf " \
|
||||||
parser_add.add_argument( 'conf', help="The conf file or directory to add to the app", nargs="?", type=str)
|
"directory, or add a config file " \
|
||||||
parser.add_argument( '--confname', help='A special name to save the conf file/directory in the persoconf directory', type=str)
|
"to an existing app" )
|
||||||
|
|
||||||
|
parser_add.add_argument( "app",
|
||||||
|
type=str,
|
||||||
|
help="The app to add, or the app to add a conf " \
|
||||||
|
"file to" )
|
||||||
|
|
||||||
|
parser_add.add_argument( "conf",
|
||||||
|
nargs="?",
|
||||||
|
type=str,
|
||||||
|
help="The conf file or directory to add to the app" )
|
||||||
|
|
||||||
|
parser_add.add_argument( "--confname",
|
||||||
|
type=str,
|
||||||
|
help="A special name to save the conf " \
|
||||||
|
"file/directory in the persoconf directory" )
|
||||||
|
|
||||||
|
|
||||||
|
# Parse arguments
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Transform paths
|
# Transform paths
|
||||||
|
|
Loading…
Reference in New Issue