parent
671bd90024
commit
755b079ab6
|
@ -6,7 +6,7 @@ import os.path
|
||||||
import utils
|
import utils
|
||||||
from metafile import Metafile, MalformedMetafileError, NoPathDefinedError
|
from metafile import Metafile, MalformedMetafileError, NoPathDefinedError
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def init(parser):
|
def init(parser):
|
||||||
|
|
||||||
parser.add_argument( "app",
|
parser.add_argument( "app",
|
||||||
|
@ -25,7 +25,7 @@ def init(parser):
|
||||||
"file/directory in the persoconf directory" )
|
"file/directory in the persoconf directory" )
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def run(args, persoconf, logger):
|
def run(args, persoconf, logger):
|
||||||
|
|
||||||
# Check (and create) the app directory
|
# Check (and create) the app directory
|
||||||
|
|
|
@ -6,7 +6,7 @@ import filecmp
|
||||||
|
|
||||||
from metafile import Metafile, MalformedMetafileError
|
from metafile import Metafile, MalformedMetafileError
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def init(parser):
|
def init(parser):
|
||||||
"""Initialize check subcommand"""
|
"""Initialize check subcommand"""
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ def init(parser):
|
||||||
"file/directory" )
|
"file/directory" )
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def run(args, persoconf, logger):
|
def run(args, persoconf, logger):
|
||||||
|
|
||||||
logger.debug("Starting 'check' command")
|
logger.debug("Starting 'check' command")
|
||||||
|
@ -128,7 +128,7 @@ def run(args, persoconf, logger):
|
||||||
logger )
|
logger )
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def _compare_and_log(original_file_path, persoconf_backup_path, logger):
|
def _compare_and_log(original_file_path, persoconf_backup_path, logger):
|
||||||
"""Compare a file with its persoconf backup and log the result (at info
|
"""Compare a file with its persoconf backup and log the result (at info
|
||||||
level if the files are matching, warning level if they are not)."""
|
level if the files are matching, warning level if they are not)."""
|
||||||
|
|
|
@ -9,7 +9,7 @@ import utils
|
||||||
from metafile import Metafile, MalformedMetafileError
|
from metafile import Metafile, MalformedMetafileError
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def init(parser):
|
def init(parser):
|
||||||
parser.add_argument( "app",
|
parser.add_argument( "app",
|
||||||
type=str,
|
type=str,
|
||||||
|
@ -28,7 +28,7 @@ def init(parser):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def run(args, persoconf, logger):
|
def run(args, persoconf, logger):
|
||||||
|
|
||||||
# Does this app really exists ?
|
# Does this app really exists ?
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def init(parser):
|
def init(parser):
|
||||||
parser.add_argument( "apps",
|
parser.add_argument( "apps",
|
||||||
type=str,
|
type=str,
|
||||||
|
@ -20,7 +20,7 @@ def init(parser):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def run(args, persoconf, logger):
|
def run(args, persoconf, logger):
|
||||||
|
|
||||||
app_list = persoconf.list_apps(logger=logger)
|
app_list = persoconf.list_apps(logger=logger)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import tarfile
|
||||||
|
|
||||||
from metafile import Metafile, MalformedMetafileError
|
from metafile import Metafile, MalformedMetafileError
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def init(parser):
|
def init(parser):
|
||||||
|
|
||||||
parser.add_argument( "apps",
|
parser.add_argument( "apps",
|
||||||
|
@ -30,7 +30,7 @@ def init(parser):
|
||||||
default="persoconf." + (time.strftime("%Y%m%d")),
|
default="persoconf." + (time.strftime("%Y%m%d")),
|
||||||
help="The name of the package to create" )
|
help="The name of the package to create" )
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def run(args, persoconf, logger):
|
def run(args, persoconf, logger):
|
||||||
|
|
||||||
pkgname = args.pkgname
|
pkgname = args.pkgname
|
||||||
|
|
|
@ -6,7 +6,7 @@ import os.path
|
||||||
import utils
|
import utils
|
||||||
from metafile import Metafile, MalformedMetafileError
|
from metafile import Metafile, MalformedMetafileError
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def init(parser):
|
def init(parser):
|
||||||
|
|
||||||
parser.add_argument( "app",
|
parser.add_argument( "app",
|
||||||
|
@ -21,7 +21,7 @@ def init(parser):
|
||||||
help="The files to update ; default to all " \
|
help="The files to update ; default to all " \
|
||||||
"added files" )
|
"added files" )
|
||||||
|
|
||||||
# --------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def run(args, persoconf, logger):
|
def run(args, persoconf, logger):
|
||||||
|
|
||||||
# app == None => update all apps
|
# app == None => update all apps
|
||||||
|
|
35
main.py
35
main.py
|
@ -21,8 +21,9 @@ import commands.list, commands.package, commands.update, commands.add, \
|
||||||
|
|
||||||
|
|
||||||
# ARGPARSE
|
# ARGPARSE
|
||||||
########################################
|
##############################################################################
|
||||||
# Argument parsing using argparse
|
# Argument parsing using argparse
|
||||||
|
# =============================================================================
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
parser.add_argument( "--rootdir",
|
parser.add_argument( "--rootdir",
|
||||||
|
@ -44,20 +45,24 @@ subparsers = parser.add_subparsers( dest="command" ,
|
||||||
title="commands" )
|
title="commands" )
|
||||||
|
|
||||||
# Help
|
# Help
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
parser_help = subparsers.add_parser( "help",
|
parser_help = subparsers.add_parser( "help",
|
||||||
help="Print this help" )
|
help="Print this help" )
|
||||||
|
|
||||||
# List
|
# List
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
parser_list = subparsers.add_parser( "list",
|
parser_list = subparsers.add_parser( "list",
|
||||||
help="List backuped apps" )
|
help="List backuped apps" )
|
||||||
commands.list.init(parser_list)
|
commands.list.init(parser_list)
|
||||||
|
|
||||||
# Package
|
# Package
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
parser_package = subparsers.add_parser( "package",
|
parser_package = subparsers.add_parser( "package",
|
||||||
help="Package a persoconf repository" )
|
help="Package a persoconf repository" )
|
||||||
commands.package.init(parser_package)
|
commands.package.init(parser_package)
|
||||||
|
|
||||||
# Update
|
# Update
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
parser_update = subparsers.add_parser( "update",
|
parser_update = subparsers.add_parser( "update",
|
||||||
help="Backup an app configuration in " \
|
help="Backup an app configuration in " \
|
||||||
"the persoconf directory with " \
|
"the persoconf directory with " \
|
||||||
|
@ -65,6 +70,7 @@ parser_update = subparsers.add_parser( "update" ,
|
||||||
commands.update.init(parser_update)
|
commands.update.init(parser_update)
|
||||||
|
|
||||||
# Add
|
# Add
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
parser_add = subparsers.add_parser( "add",
|
parser_add = subparsers.add_parser( "add",
|
||||||
help="Add an app to the persoconf " \
|
help="Add an app to the persoconf " \
|
||||||
"directory, or add a config file " \
|
"directory, or add a config file " \
|
||||||
|
@ -72,12 +78,14 @@ parser_add = subparsers.add_parser( "add" ,
|
||||||
commands.add.init(parser_add)
|
commands.add.init(parser_add)
|
||||||
|
|
||||||
# Check
|
# Check
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
parser_check = subparsers.add_parser( "check",
|
parser_check = subparsers.add_parser( "check",
|
||||||
help="Checks if the backuped and the " \
|
help="Checks if the backuped and the " \
|
||||||
"original file are different." )
|
"original file are different." )
|
||||||
commands.check.init(parser_check)
|
commands.check.init(parser_check)
|
||||||
|
|
||||||
# Delete
|
# Delete
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
parser_del = subparsers.add_parser( "delete",
|
parser_del = subparsers.add_parser( "delete",
|
||||||
help="Delete an app from the persoconf " \
|
help="Delete an app from the persoconf " \
|
||||||
"directory, or a config file from " \
|
"directory, or a config file from " \
|
||||||
|
@ -85,13 +93,14 @@ parser_del = subparsers.add_parser( "delete" ,
|
||||||
commands.delete.init(parser_del)
|
commands.delete.init(parser_del)
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
|
# =============================================================================
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Transform paths
|
# Transform paths
|
||||||
args.rootdir = os.path.expanduser(args.rootdir)
|
args.rootdir = os.path.expanduser(args.rootdir)
|
||||||
|
|
||||||
# LOGGING
|
# LOGGING
|
||||||
########################################
|
##############################################################################
|
||||||
log = logging.getLogger("persoconf")
|
log = logging.getLogger("persoconf")
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
@ -110,13 +119,14 @@ log_handler_console.setFormatter(log_formatter_console)
|
||||||
log.addHandler(log_handler_console)
|
log.addHandler(log_handler_console)
|
||||||
|
|
||||||
# SCRIPT
|
# SCRIPT
|
||||||
########################################
|
##############################################################################
|
||||||
# If we were asked for help, let's give some
|
# If we were asked for help, let's give some
|
||||||
if args.command in [ "help", None ]:
|
if args.command in [ "help", None ]:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# Try to create the Persoconf
|
# Try to create the Persoconf
|
||||||
|
# =============================================================================
|
||||||
try:
|
try:
|
||||||
persoconf = Persoconf(path=args.rootdir, metafile=args.metafile)
|
persoconf = Persoconf(path=args.rootdir, metafile=args.metafile)
|
||||||
|
|
||||||
|
@ -151,38 +161,31 @@ except PersoconfRootDoesNotExistError:
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# LIST COMMAND
|
# LIST COMMAND
|
||||||
########################################
|
# =============================================================================
|
||||||
if args.command == "list":
|
if args.command == "list":
|
||||||
commands.list.run(args, persoconf, log)
|
commands.list.run(args, persoconf, log)
|
||||||
|
|
||||||
# DELETE COMMAND
|
# DELETE COMMAND
|
||||||
########################################
|
# =============================================================================
|
||||||
if args.command == "delete":
|
if args.command == "delete":
|
||||||
commands.delete.run(args, persoconf, log)
|
commands.delete.run(args, persoconf, log)
|
||||||
|
|
||||||
# ADD COMMAND
|
# ADD COMMAND
|
||||||
########################################
|
# =============================================================================
|
||||||
if args.command == "add":
|
if args.command == "add":
|
||||||
commands.add.run(args, persoconf, log)
|
commands.add.run(args, persoconf, log)
|
||||||
|
|
||||||
# CHECK COMMAND
|
# CHECK COMMAND
|
||||||
########################################
|
# =============================================================================
|
||||||
if args.command == "check":
|
if args.command == "check":
|
||||||
commands.check.run(args, persoconf, log)
|
commands.check.run(args, persoconf, log)
|
||||||
|
|
||||||
# UPDATE COMMAND
|
# UPDATE COMMAND
|
||||||
########################################
|
# =============================================================================
|
||||||
if args.command == "update":
|
if args.command == "update":
|
||||||
commands.update.run(args, persoconf, log)
|
commands.update.run(args, persoconf, log)
|
||||||
|
|
||||||
# PACKAGE COMMAND
|
# PACKAGE COMMAND
|
||||||
########################################
|
# =============================================================================
|
||||||
if args.command == "package":
|
if args.command == "package":
|
||||||
commands.package.run(args, persoconf, log)
|
commands.package.run(args, persoconf, log)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
########################################
|
|
||||||
|
|
Loading…
Reference in New Issue