Add commands module. Move list command inside.
parent
7a8215ae16
commit
1749d0706d
|
@ -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)
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue