Newer
Older
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Started 18/05/2011 by Seblu <seblu@seblu.net>
'''
InstallSystems Installation Tool
'''
import os
from installsystems.printer import *
from installsystems.repository import RepositoryCache
from installsystems.image import PackageImage
# The following import can be removed when min version will be python 2.7
import installsystems.argparse as argparse
class DebugAction(argparse.Action):
'''Set installsystems in debug mode. Argparse callback'''
def __call__(self, parser, namespace, values, option_string=None):
if installsystems.debug == False:
installsystems.debug = True
debug("Debug on")
p_main.add_argument("-V", "--version", action="version", version=installsystems.version,
help="show installsystems version")
p_main.add_argument('-d', "--debug", action=DebugAction, nargs=0,
help="active debug mode")
p_main.add_argument('-q', "--quiet", action="store_false", dest="verbose", default=True,
help="active quiet mode")
p_main.add_argument("-c", "--config", dest="config", type=str, default=None,
help="config file path")
p_main.add_argument("-v", "--image-version", dest="image_version", type=int, default=None,
help="image version")
p_main.add_argument("-t", "--timeout", dest="timeout", type=int, default=3,
help="download timeout")
p_main.add_argument("image_name", type=str,
help="image to install (path or name)")
try:
# Partial parse
args = p_main.parse_known_args()[0]
image_name_type = istools.pathtype(args.image_name)
pkg = PackageImage(istools.abspath(args.image_name))
repocache = RepositoryCache(config.cache, timeout=args.timeout, verbose=args.verbose)
# update remote info
repocache.update()
# get image package
pkg = repocache.get(args.image_name, args.image_version)
p_main.print_usage()
exit(1)
# install start time
t0 = time.time()
# call parser again, with extended attributes
args = p_main.parse_args()
# run setup scripts
# compute building time
t1 = time.time()
dt = int(t1 - t0)
arrow("Install time: %s" % datetime.timedelta(seconds=dt), 1, args.verbose)
except KeyboardInterrupt:
warn("Keyboard Interrupted")