Commit 8273db6b authored by Seblu's avatar Seblu
Browse files

Improve arrow and printer

Arrow is now relative this allow to pass context of arrow
no more verbose mode. Soft is verbose except in quiet mode
parent a0d18a5d
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -14,19 +14,20 @@ import installsystems.argparse as argparse # To remove when default to python 2.
from installsystems.printer import *
from installsystems.image import SourceImage

class DebugAction(argparse.Action):
    '''Set installsystems in debug mode. Argparse callback'''
class ISAction(argparse.Action):
    '''Set installsystems quiet/debug mode. Argparse callback'''
    def __call__(self, parser, namespace, values, option_string=None):
        if installsystems.debug == False:
        if option_string in ("-q", "--quiet"):
            installsystems.quiet = True
        elif option_string in ("-d", "--debug"):
            installsystems.debug = True
            debug("Debug on")


def init(args):
    '''Create an empty fresh source image tree'''
    # call init from library
    try:
        simg = SourceImage.create(args.path, args.verbose)
        simg = SourceImage.create(args.path)
    except Exception as e:
        error("init failed: %s." % e)

@@ -42,7 +43,7 @@ def build(args):
        # compute building time
        t1 = time.time()
        dt = int(t1 - t0)
        arrow("Build time: %s" % datetime.timedelta(seconds=dt), 1, args.verbose)
        arrow("Build time: %s" % datetime.timedelta(seconds=dt))
    except Exception as e:
        error("build failed: %s." % e)

@@ -50,9 +51,9 @@ def build(args):
p_main = argparse.ArgumentParser()
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,
p_main.add_argument('-d', "--debug", action=ISAction, nargs=0,
                    help="active debug mode")
p_main.add_argument('-q', "--quiet", action="store_false", dest="verbose", default=True,
p_main.add_argument('-q', "--quiet", action=ISAction, nargs=0,
                    help="active quiet mode")

subparsers = p_main.add_subparsers()
+11 −11
Original line number Diff line number Diff line
@@ -17,22 +17,22 @@ from installsystems.repository import RepositoryManager, RepositoryConfig
from installsystems.image import PackageImage
from installsystems.config import ConfigFile


class DebugAction(argparse.Action):
    '''Set installsystems in debug mode. Argparse callback'''
class ISAction(argparse.Action):
    '''Set installsystems quiet/debug mode. Argparse callback'''
    def __call__(self, parser, namespace, values, option_string=None):
        if installsystems.debug == False:
        if option_string in ("-q", "--quiet"):
            installsystems.debug = False
        elif option_string in ("-d", "--debug"):
            installsystems.debug = True
            debug("Debug on")


# Argument parsing loading
p_main = argparse.ArgumentParser()
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,
p_main.add_argument('-d', "--debug", action=ISAction, nargs=0,
                    help="active debug mode")
p_main.add_argument('-q', "--quiet", action="store_false", dest="verbose", default=True,
p_main.add_argument('-q', "--quiet", action=ISAction, nargs=0,
                    help="active quiet mode")
p_main.add_argument("--no-cache", action="store_false", default=False,
                    help="Not use persistent db caching")
@@ -59,7 +59,7 @@ try:
        if args.no_cache:
            config.cache = None
        # init repo cache object
        repoman = RepositoryManager(config.cache, timeout=args.timeout, verbose=args.verbose)
        repoman = RepositoryManager(config.cache, timeout=args.timeout)
        # register config repositories
        for crepo in config.repos:
            repoman.register(crepo)
@@ -76,14 +76,14 @@ try:
    # run parser scripts with parser parser argument
    pkg.run_parser(parser=p_main)
    # call parser again, with extended attributes
    arrow("Parsing arguments", 1, args.verbose)
    args = p_main.parse_args()
    arrow("Parsing arguments")
    args = p_main.parse_args(namespace=args)
    # run setup scripts
    pkg.run_setup(namespace = args)
    # compute building time
    t1 = time.time()
    dt = int(t1 - t0)
    arrow("Install time: %s" % datetime.timedelta(seconds=dt), 1, args.verbose)
    arrow("Install time: %s" % datetime.timedelta(seconds=dt))
except Exception as e:
    error(e)
except KeyboardInterrupt:
+11 −10
Original line number Diff line number Diff line
@@ -14,27 +14,28 @@ from installsystems.repository import Repository, RepositoryConfig
from installsystems.image import PackageImage
from installsystems.config import ConfigFile

class DebugAction(argparse.Action):
    '''Set installsystems in debug mode. Argparse callback'''
class ISAction(argparse.Action):
    '''Set installsystems quiet/debug mode. Argparse callback'''
    def __call__(self, parser, namespace, values, option_string=None):
        if installsystems.debug == False:
        if option_string in ("-q", "--quiet"):
            installsystems.quiet = True
        elif option_string in ("-d", "--debug"):
            installsystems.debug = True
            debug("Debug on")


def init(args):
    '''Create an empty fresh repo tree'''
    # call init from library
    try:
        Repository.create(args.repository, verbose=args.verbose)
        Repository.create(args.repository)
    except Exception as e:
        raise Exception("init failed: %s" % e)

def add(args):
    '''Add a package to repository'''
    try:
        repo = Repository(args.repository, verbose=args.verbose)
        pkg = PackageImage(args.path, verbose=args.verbose)
        repo = Repository(args.repository)
        pkg = PackageImage(args.path)
        repo.add(pkg)
    except Exception as e:
        raise Exception("add failed: %s" % e)
@@ -42,7 +43,7 @@ def add(args):
def delete(args):
    '''Remove a package from repository'''
    try:
        repo = Repository(args.repository, verbose=args.verbose)
        repo = Repository(args.repository)
        repo.delete(args.image_name, args.image_version)
    except Exception as e:
        raise Exception("del failed: %s" % e)
@@ -51,9 +52,9 @@ def delete(args):
p_main = argparse.ArgumentParser()
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,
p_main.add_argument('-d', "--debug", action=ISAction, nargs=0,
                    help="active debug mode")
p_main.add_argument('-q', "--quiet", action="store_false", dest="verbose", default=True,
p_main.add_argument('-q', "--quiet", action=ISAction, nargs=0,
                    help="active quiet mode")
p_main.add_argument("-c", "--config", dest="config", type=str, default=None,
                    help="config file path")
+1 −0
Original line number Diff line number Diff line
@@ -9,5 +9,6 @@ InstallSystems module
canonical_name="installsystems"
version = "1-dev"
debug = False
quiet = False

__all__ = []
+11 −10
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ class Database(object):
    db_format = "1"

    @classmethod
    def create(cls, path, verbose=True):
        arrow("Creating repository database", 1, verbose)
    def create(cls, path):
        arrow("Creating repository database")
        # check locality
        if istools.pathtype(path) != "file":
            raise NotImplementedError("Database creation must be local")
@@ -40,14 +40,13 @@ class Database(object):
            conn.close()
        except Exception as e:
            raise Exception("Create database failed: %s" % e)
        return cls(path, verbose)
        return cls(path)

    def __init__(self, path, verbose=True):
    def __init__(self, path):
        # check locality
        if istools.pathtype(path) != "file":
            raise NotImplementedError("Database creation must be local")
        self.path = os.path.abspath(path)
        self.verbose = verbose
        self.conn = sqlite3.connect(self.path, isolation_level=None)
        self.conn.execute("PRAGMA foreign_keys = ON")

@@ -77,10 +76,11 @@ class Database(object):
        '''Add a packaged image to a db'''
        try:
            # let's go
            arrow("Begin transaction to db", 1, self.verbose)
            arrow("Begin transaction to db")
            arrowlevel(1)
            self.conn.execute("BEGIN TRANSACTION")
            # insert image information
            arrow("Add image metadata", 2, self.verbose)
            arrow("Add image metadata")
            self.conn.execute("INSERT OR REPLACE INTO image values (?,?,?,?,?,?,?)",
                              (image.md5,
                               image.name,
@@ -91,7 +91,7 @@ class Database(object):
                               image.size,
                               ))
            # insert data informations
            arrow("Add payload metadata", 2, self.verbose)
            arrow("Add payload metadata")
            for name, obj in image.payload.items():
                self.conn.execute("INSERT OR REPLACE INTO payload values (?,?,?,?,?)",
                                  (obj.md5,
@@ -101,14 +101,15 @@ class Database(object):
                                   obj.size,
                                   ))
            # on commit
            arrow("Commit transaction to db", 1, self.verbose)
            arrow("Commit transaction to db")
            self.conn.execute("COMMIT TRANSACTION")
            arrowlevel(-1)
        except Exception as e:
            raise Exception("Adding metadata fail: %s" % e)

    def delete(self, name, version):
        '''Delete a packaged image'''
        arrow("Removing metadata from db", 1, self.verbose)
        arrow("Removing metadata from db")
        # check locality
        if istools.pathtype(self.path) != "file":
            raise NotImplementedError("Database deletion must be local")
Loading