diff --git a/persoconf/main.py b/persoconf/main.py index 160de6a..fdf0109 100755 --- a/persoconf/main.py +++ b/persoconf/main.py @@ -64,11 +64,14 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True): return False 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 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 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) 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 except FileExistsError: @@ -149,9 +153,12 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True): shutil.rmtree(dst + ".bak") 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: - 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 except NotADirectoryError: @@ -160,7 +167,9 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True): os.remove(dst + ".bak") 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. @@ -172,12 +181,23 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True): ######################################## # Argument parsing using argparse 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( '--verbose', "-v", help='Spout out more logs', action="store_true") + +parser.add_argument( "--rootdir", + 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 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") # Package -parser_package = subparsers.add_parser("package", help="Package a persoconf repository") -parser_package.add_argument( "apps", type=str, help="The apps to package ; defaults to all apps", nargs="*", default=[] ) -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 = subparsers.add_parser( "package", + help="Package a persoconf repository" ) + +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 -parser_update = subparsers.add_parser("update", help="Backup an app configuration in the persoconf directory with the configuration in use now") -parser_update.add_argument( 'app', help='The app to update', type=str ) -parser_update.add_argument( 'files', help='The files to update ; default to all added files', type=str, nargs="*", default=[]) +parser_update = subparsers.add_parser( "update", + help="Backup an app configuration in " \ + "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 -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.add_argument( 'app', help="The app to add, or the app to add a conf file to", type=str) -parser_add.add_argument( 'conf', help="The conf file or directory to add to the app", nargs="?", type=str) -parser.add_argument( '--confname', help='A special name to save the conf file/directory in the persoconf directory', type=str) +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.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() # Transform paths