def __init__(self):
args = None
parser = OptionParser(
prog="chirribackup",
description="%prog is a cheap and ugly backup tool written with love.",
version="%prog 1.0",
usage="%s [options] {directory} {action} [action args...]" % sys.argv[0],
epilog="Use 'help' action for more information. Other valid commands: %s" \
% " ".join(ActionsManager.action_handlers.keys())
)
parser.add_option("-D", "--debug",
dest="verbosity",
action="store_const",
const="DEBUG",
help="Debug verbosity level.")
parser.add_option("-l", "--log-file",
dest="logfile",
default=None,
help="Log file")
parser.add_option("-v", "--verbosity",
type="str",
dest="verbosity",
default="INFO",
help="The log verbosity level. Accepted values: CRITICAL, ERROR, WARNING, INFO (default), DEBUG, DEBUG2")
try:
(self.options, args) = parser.parse_args()
if self.options.logfile is not None:
logger.to_file(self.options.logfile)
if self.options.verbosity is not None:
logger.setLogLevel(self.options.verbosity)
if len(args) < 1:
parser.error("Target {directory} not specified.")
self.options.path = args[0]
self.options.args = args[1:]
if len(args) == 1 and args[0] == "help":
self.options.path = None
self.options.args = args
elif len(args) == 2 and args[0] == "help" and args[1] == "help":
self.options.path = None
self.options.args = args
else:
if not os.path.exists(self.options.path):
logger.warning("Target directory '%s' does not exist." % self.options.path)
elif not os.path.isdir(self.options.path):
parser.error("Target directory '%s' is not a directory." % self.options.path)
except (OptionError, TypeError), e:
parser.error(e)
# Singleton container class
评论列表
文章目录