diff --git a/persoconf/commands/__init__.py b/persoconf/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/persoconf/commands/list.py b/persoconf/commands/list.py new file mode 100644 index 0000000..c50487f --- /dev/null +++ b/persoconf/commands/list.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os.path + +# -------------------------------------- +def init(parser): + parser.add_argument( "apps" , + type=str , + nargs="*" , + default=[] , + help="The apps to list ; defaults to all " \ + "apps" ) + + parser.add_argument( "--show-files", "-f" , + action="store_true" , + help="Show the files for each app ; it is " \ + "automatically set if you specify the " \ + "apps to list." ) + + + +# -------------------------------------- +def run(args, persoconf, logger): + + app_list = persoconf.list_apps(logger=logger) + + # If no app is given: list all apps + if args.apps == []: + logger.info("Listing all apps") + for app in app_list: + # Print the app name + print(app) + + # Print the files too if asked so + if args.show_files: + for f in app_list[app].files: + if os.path.isdir(persoconf.path + "/" + app + "/" + f): + print("\t%s/" % f) + else: + print("\t%s" % f) + + # Some apps were specified, so we list them with their files + else: + for app in args.apps: + if app not in app_list: + logger.warning("No such app: %s" % app) + continue + + # Print the app name + print(app) + + # Print the app files + for f in app_list[app].files: + if os.path.isdir(persoconf.path + "/" + app + "/" + f): + print("\t%s/" % f) + else: + print("\t%s" % f) diff --git a/persoconf/main.py b/persoconf/main.py index 093c5cb..6a482ce 100755 --- a/persoconf/main.py +++ b/persoconf/main.py @@ -15,6 +15,8 @@ from metafile import Metafile, MalformedMetafileError, NoPathDefinedError from persoconf import Persoconf, FileInsteadOfDirError, \ PersoconfRootDoesNotExistError +import commands.list + # ARGPARSE @@ -47,19 +49,7 @@ parser_help = subparsers.add_parser( "help" , # List parser_list = subparsers.add_parser( "list" , help="List backuped apps" ) - -parser_list.add_argument( "apps" , - type=str , - nargs="*" , - default=[] , - help="The apps to list ; defaults to all " \ - "apps" ) - -parser_list.add_argument( "--show-files", "-f" , - action="store_true" , - help="Show the files for each app ; it is " \ - "automatically set if you specify the apps " \ - "to list." ) +commands.list.init(parser_list) # Package parser_package = subparsers.add_parser( "package" , @@ -215,40 +205,7 @@ except PersoconfRootDoesNotExistError: # LIST COMMAND ######################################## if args.command == "list": - - app_list = persoconf.list_apps(logger=log) - - # If no app is given: list all apps - if args.apps == []: - log.info("Listing all apps") - for app in app_list: - # Print the app name - print(app) - - # Print the files too if asked so - if args.show_files: - for f in app_list[app].files: - if os.path.isdir(persoconf.path + "/" + app + "/" + f): - print("\t%s/" % f) - else: - print("\t%s" % f) - - # Some apps were specified, so we list them with their files - else: - for app in args.apps: - if app not in app_list: - log.warning("No such app: %s" % app) - continue - - # Print the app name - print(app) - - # Print the app files - for f in app_list[app].files: - if os.path.isdir(persoconf.path + "/" + app + "/" + f): - print("\t%s/" % f) - else: - print("\t%s" % f) + commands.list.run(args, persoconf, log) # DELETE COMMAND