persoconf/commands/list.py

59 lines
2.1 KiB
Python
Raw Normal View History

#!/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:
2015-12-07 12:24:29 -05:00
if os.path.isdir( os.path.join(persoconf.path, app, f) ):
print("\t%s/" % f)
else:
2015-12-07 12:24:29 -05:00
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:
2015-12-07 12:24:29 -05:00
print("\t%s" % f)