diff --git a/bin/isimage b/bin/isimage index 611dc3328a66096976518f431a5454c3e6040a07..f2ec719af292351f82fdd1fb134c5753221b2fc6 100755 --- a/bin/isimage +++ b/bin/isimage @@ -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() diff --git a/bin/isinstall b/bin/isinstall index 84a74e0bcbf83712e82c60c3827cad938c421c80..8dd7db8b2786d745054c2e45a24dcdf564ae69fe 100755 --- a/bin/isinstall +++ b/bin/isinstall @@ -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: diff --git a/bin/isrepo b/bin/isrepo index e7841e8e5caf74ff86bab14ea8e1c08df7b098be..0c137cff4f905589f2a730e129ba8f53f0b369d5 100755 --- a/bin/isrepo +++ b/bin/isrepo @@ -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") diff --git a/installsystems/__init__.py b/installsystems/__init__.py index 4f5d9eab0741fe4ab74141fda0686cb9ae246bf9..75378672dd619eb1c474b9971e45561bb549db17 100644 --- a/installsystems/__init__.py +++ b/installsystems/__init__.py @@ -9,5 +9,6 @@ InstallSystems module canonical_name="installsystems" version = "1-dev" debug = False +quiet = False __all__ = [] diff --git a/installsystems/database.py b/installsystems/database.py index a774b144217ae491fc13aa426770cb43d7c0cb6a..cd78da9357d71cad2f6a4ca7e0480553da8b908b 100644 --- a/installsystems/database.py +++ b/installsystems/database.py @@ -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") diff --git a/installsystems/image.py b/installsystems/image.py index fdead34c384dbc34cc6557504b8245b7e3faa530..3f8570336cf82e1df04bf26ce9aed7924920516c 100644 --- a/installsystems/image.py +++ b/installsystems/image.py @@ -52,7 +52,7 @@ class SourceImage(Image): ''' @classmethod - def create(cls, path, verbose=True): + def create(cls, path): ''' Create an empty source image ''' @@ -64,7 +64,7 @@ class SourceImage(Image): setup_path = os.path.join(path, "setup") payload_path = os.path.join(path, "payload") # create base directories - arrow("Creating base directories", 1, verbose) + arrow("Creating base directories") try: for d in (path, parser_path, setup_path, payload_path): if not os.path.exists(d) or not os.path.isdir(d): @@ -72,22 +72,23 @@ class SourceImage(Image): except Exception as e: raise Exception("Unable to create directory: %s: %s" % (d, e)) # create example files - arrow("Creating examples", 1, verbose) + arrow("Creating examples") + arrowlevel(1) try: # create description example from template - arrow("Creating description example", 2, verbose) + arrow("Creating description example") open(os.path.join(path, "description"), "w").write(istemplate.description) # create parser example from template - arrow("Creating parser script example", 2, verbose) + arrow("Creating parser script example") open(os.path.join(parser_path, "01-parser.py"), "w").write(istemplate.parser) # create setup example from template - arrow("Creating setup script example", 2, verbose) + arrow("Creating setup script example") open(os.path.join(setup_path, "01-setup.py"), "w").write(istemplate.setup) except Exception as e: raise Exception("Unable to example file: %s" % e) try: # setting rights on files in setup and parser - arrow("Setting executable rights on scripts", 2, verbose) + arrow("Setting executable rights on scripts") umask = os.umask(0) os.umask(umask) for dpath in (parser_path, setup_path): @@ -95,9 +96,10 @@ class SourceImage(Image): istools.chrights(os.path.join(dpath, f), mode=0777 & ~umask) except Exception as e: raise Exception("Unable to set rights on %s: %s" % (pf, e)) - return cls(path, verbose) + arrowlevel(-1) + return cls(path) - def __init__(self, path, verbose=True): + def __init__(self, path): # check local repository if istools.pathtype(path) != "file": raise NotImplementedError("SourceImage must be local") @@ -106,7 +108,6 @@ class SourceImage(Image): self.parser_path = os.path.join(path, "parser") self.setup_path = os.path.join(path, "setup") self.payload_path = os.path.join(path, "payload") - self.verbose = verbose self.validate_source_files() self.description = self.parse_description() # script tarball path @@ -147,28 +148,29 @@ class SourceImage(Image): Create a script tarball in current directory ''' # create tarball - arrow("Creating image tarball", 1, self.verbose) - arrow("Name %s" % self.image_name, 2, self.verbose) + arrow("Creating image tarball") + arrowlevel(1) + arrow("Name %s" % self.image_name) try: tarball = Tarball.open(self.image_name, mode="w:gz", dereference=True) except Exception as e: raise Exception("Unable to create tarball %s: %s" % (self.image_name, e)) # add .description.json - arrow("Add description.json", 2, self.verbose) + arrow("Add description.json") tarball.add_str("description.json", description, tarfile.REGTYPE, 0444) # add .format - arrow("Add format", 2, self.verbose) + arrow("Add format") tarball.add_str("format", self.format, tarfile.REGTYPE, 0444) # add parser scripts - arrow("Add parser scripts", 2, self.verbose) + arrow("Add parser scripts") tarball.add(self.parser_path, arcname="parser", recursive=True, filter=self._tar_scripts_filter) # add setup scripts - arrow("Add setup scripts", 2, self.verbose) tarball.add(self.setup_path, arcname="setup", recursive=True, filter=self._tar_scripts_filter) # closing tarball file tarball.close() + arrowlevel(-1) def _create_payloads(self): ''' @@ -176,11 +178,13 @@ class SourceImage(Image): Doesn't compute md5 during creation because tarball can be created manually ''' - arrow("Creating payloads", 1, self.verbose) + arrow("Creating payloads") + arrowlevel(1) # build list of payload files candidates = os.listdir(self.payload_path) if len(candidates) == 0: - arrow("No payload", 2, self.verbose) + arrow("No payload") + arrowlevel(-1) return [] # create payload files l_l = [] @@ -193,9 +197,9 @@ class SourceImage(Image): source_stat = os.stat(source_path) isdir = stat.S_ISDIR(source_stat.st_mode) if os.path.exists(dest_path): - arrow("Payload %s already exists" % dest_path, 2, self.verbose) + arrow("Payload %s already exists" % dest_path) else: - arrow("Creating payload %s" % dest_path, 2, self.verbose) + arrow("Creating payload %s" % dest_path) if isdir: self._create_payload_tarball(dest_path, source_path) else: @@ -207,6 +211,7 @@ class SourceImage(Image): payobj.mode = stat.S_IMODE(source_stat.st_mode) payobj.mtime = source_stat.st_mtime l_l.append(payobj) + arrowlevel(-1) return l_l def _create_payload_tarball(self, tar_path, data_path): @@ -255,17 +260,19 @@ class SourceImage(Image): ''' Generate a JSON description file ''' - arrow("Generating JSON description", 1, self.verbose) + arrow("Generating JSON description") + arrowlevel(1) # copy description desc = self.description.copy() # timestamp image - arrow("Timestamping", 2, self.verbose) + arrow("Timestamping") desc["date"] = int(time.time()) # append payload infos - arrow("Checksumming", 2, self.verbose) + arrow("Checksumming") desc["payload"] = {} for payload in payloads: desc["payload"][payload.name] = payload.info + arrowlevel(-1) # serialize return json.dumps(desc) @@ -273,7 +280,7 @@ class SourceImage(Image): ''' Raise an exception is description file is invalid and return vars to include ''' - arrow("Parsing description", 1, self.verbose) + arrow("Parsing description") d = dict() try: descpath = os.path.join(self.base_path, "description") @@ -291,15 +298,14 @@ class PackageImage(Image): Packaged image manipulation class ''' - def __init__(self, path, md5name=False, verbose=True): + def __init__(self, path, md5name=False): Image.__init__(self) self.path = istools.abspath(path) self.base_path = os.path.dirname(self.path) - self.verbose = verbose # tarball are named by md5 and not by real name self.md5name = md5name # load image in memory - arrow("Loading tarball in memory", 1, verbose) + arrow("Loading tarball in memory") memfile = cStringIO.StringIO() fo = istools.uopen(self.path) (self.size, self.md5) = istools.copyfileobj(fo, memfile) @@ -346,34 +352,38 @@ class PackageImage(Image): Parse tarball and return metadata dict ''' # extract metadata - arrow("Read tarball metadata", 1, self.verbose) + arrow("Read tarball metadata", 1) + arrowlevel(1) img_format = self._tarball.get_str("format") img_desc = self._tarball.get_str("description.json") # check format - arrow("Read format file", 2, self.verbose) + arrow("Read format file") if img_format != self.format: raise Exception("Invalid tarball image format") # check description - arrow("Read image description", 2, self.verbose) + arrow("Read image description") try: desc = json.loads(img_desc) except Exception as e: raise Exception("Invalid description: %s" % e) # FIXME: we should check valid information here + arrowlevel(-1) return desc def check(self, message="Check MD5"): ''' Check md5 and size of tarballs are correct ''' - arrow(message, 1, self.verbose) + arrow(message) + arrowlevel(1) # check image if self.md5 != istools.md5sum(self.path): raise Exception("Invalid MD5 of image %s" % self.name) # check payloads for pay_name, pay_obj in self.payload.items(): - arrow(pay_name, 2, self.verbose) + arrow(pay_name) pay_obj.check() + arrowlevel(-1) def run_parser(self, **kwargs): ''' @@ -391,14 +401,16 @@ class PackageImage(Image): ''' Run scripts in a tarball directory ''' - arrow("Run %s scripts" % directory, 1, self.verbose) + arrow("Run %s scripts" % directory) + arrowlevel(1) # get list of parser scripts l_scripts = self._tarball.getnames("%s/.*\.py" % directory) # order matter! l_scripts.sort() # run scripts for n_scripts in l_scripts: - arrow(os.path.basename(n_scripts), 2, self.verbose) + arrow(os.path.basename(n_scripts)) + old_level = arrowlevel(1) # extract source code try: s_scripts = self._tarball.get_str(n_scripts) @@ -422,6 +434,8 @@ class PackageImage(Image): except Exception as e: raise Exception("Execution script %s fail: %s" % (n_scripts, e)) + arrowlevel(level=old_level) + arrowlevel(-1) class Payload(object): diff --git a/installsystems/printer.py b/installsystems/printer.py index 59469e05e4c0d0b943925e989cc44e147d1af364..8f40c1afdb67a41b78431f81023635f8d14719c4 100644 --- a/installsystems/printer.py +++ b/installsystems/printer.py @@ -27,6 +27,10 @@ color = { "reset": "\033[m", } +# arrow_level is between 1 and 3 +# is the level of indentation of arrow +_arrow_level = 1 + def out(message="", fd=sys.stdout, endl=os.linesep, flush=True): '''Print message colorised in fd ended by endl''' # color subsitution @@ -59,18 +63,36 @@ def warn(message, fd=sys.stderr, endl=os.linesep): out("#light##yellow#Warning:#reset# #yellow#%s#reset#" % message, fd, endl) def info(message, fd=sys.stderr, endl=os.linesep): - out("#light#Info%s:#reset# %s" % message, fd, endl) + if not installsystems.quiet: + out("#light#Info%s:#reset# %s" % message, fd, endl) def debug(message, fd=sys.stderr, endl=os.linesep): if installsystems.debug: out("#light##black#%s#reset#" % message, fd, endl) -def arrow(message, level=1, verbose=True, fd=sys.stdout, endl=os.linesep): - if not verbose: +def arrowlevel(inc=None,level=None): + global _arrow_level + old_level = _arrow_level + if level is not None: + _arrow_level = max(1, min(4, level)) + if inc is not None: + _arrow_level = max(1, min(4, _arrow_level + inc)) + return old_level + +def arrow(message, level=None, fd=sys.stdout, endl=os.linesep): + if installsystems.quiet: return - if level == 1: + # set a one shot level + if level is not None: + old_level = arrowlevel(level=level) + if _arrow_level == 1: out("#light##red#=>#reset# %s" % message) - elif level == 2: + elif _arrow_level == 2: out(" #light##yellow#=>#reset# %s" % message) - elif level == 3: - out(" #light##purple#=>#reset# %s" % message) + elif _arrow_level == 3: + out(" #light##blue#=>#reset# %s" % message) + elif _arrow_level == 4: + out(" #light##green#=>#reset# %s" % message) + # restore old on one shot level + if level is not None: + arrowlevel(level=old_level) diff --git a/installsystems/repository.py b/installsystems/repository.py index 1b0557483f0d5f463883d32a06a3a5a65b42ab3c..e6ee69e34cd25115edf9f68f56a1f16aaa2e10fb 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -21,37 +21,39 @@ from installsystems.image import Image, PackageImage from installsystems.database import Database class Repository(object): - ''' Repository class + ''' + Repository class ''' - def __init__(self, config, verbose=True): - self.verbose = verbose + def __init__(self, config): self.config = config - self.db = Database(config.dbpath, verbose=self.verbose) + self.db = Database(config.dbpath) @classmethod - def create(cls, config, verbose=True): + def create(cls, config): '''Create an empty base repository''' # check local repository if istools.pathtype(config.path) != "file": raise NotImplementedError("Repository creation must be local") # create base directories - arrow("Creating base directories", 1, verbose) + arrow("Creating base directories") + arrowlevel(1) # creating local directory try: if os.path.exists(config.path): - arrow("%s already exists" % config.path, 2, verbose) + arrow("%s already exists" % config.path) else: istools.mkdir(config.path, config.uid, config.gid, config.dmod) - arrow("%s directory created" % config.path, 2, verbose) + arrow("%s directory created" % config.path) except Exception as e: raise Exception("Unable to create directory %s: %s" % (config.path, e)) + arrowlevel(-1) # create database dbpath = os.path.join(config.path, config.dbname) - d = Database.create(dbpath, verbose=verbose) + d = Database.create(dbpath) istools.chrights(dbpath, uid=config.uid, gid=config.gid, mode=config.fmod) # create last file - self = cls(config, verbose) + self = cls(config) self.update_last() return self @@ -61,7 +63,7 @@ class Repository(object): if istools.pathtype(self.config.path) != "file": raise NotImplementedError("Repository addition must be local") try: - arrow("Updating last file", 1, self.verbose) + arrow("Updating last file") last_path = os.path.join(self.config.path, self.config.lastname) open(last_path, "w").write("%s\n" % int(time.time())) istools.chrights(last_path, self.config.uid, self.config.gid, self.config.fmod) @@ -85,19 +87,21 @@ class Repository(object): # checking data tarballs md5 before copy image.check("Check image and payload before copy") # adding file to repository - arrow("Copying images and payload", 1, self.verbose) + arrow("Copying images and payload") + arrowlevel(1) for obj in [ image ] + image.payload.values(): dest = os.path.join(self.config.path, obj.md5) basesrc = os.path.basename(obj.path) if os.path.exists(dest): - arrow("Skipping %s: already exists" % basesrc, 2, self.verbose) + arrow("Skipping %s: already exists" % basesrc) else: - arrow("Adding %s (%s)" % (basesrc, obj.md5), 2, self.verbose) + arrow("Adding %s (%s)" % (basesrc, obj.md5)) istools.copy(obj.path, dest, self.config.uid, self.config.gid, self.config.fmod) + arrowlevel(-1) # copy is done. create a image inside repo r_image = PackageImage(os.path.join(self.config.path, image.md5), - md5name=True, verbose=self.verbose) + md5name=True) # checking must be done with original md5 r_image.md5 = image.md5 # checking image and payload after copy @@ -117,23 +121,27 @@ class Repository(object): if desc is None: error("Unable to find %s version %s in database" % (name, version)) # removing script tarballs - arrow("Removing script tarball", 1, self.verbose) + arrow("Removing script tarball") + arrowlevel(1) tpath = os.path.join(self.config.path, "%s-%s%s" % (name, version, Image.extension)) if os.path.exists(tpath): os.unlink(tpath) - arrow("%s removed" % os.path.basename(tpath), 2, self.verbose) + arrow("%s removed" % os.path.basename(tpath)) + arrowlevel(1) # removing data tarballs - arrow("Removing data tarballs", 1, self.verbose) + arrow("Removing data tarballs") + arrowlevel(1) for tb in self.db.databalls(name, version): tpath = os.path.join(self.config.data, tb) if os.path.exists(tpath): os.unlink(tpath) - arrow("%s removed" % tb, 2, self.verbose) + arrow("%s removed" % tb) + arrowlevel(-1) # removing metadata self.db.delete(name, version) # update last file - arrow("Updating last file", 1, self.verbose) + arrow("Updating last file") self.update_last() def has(self, name, version): @@ -148,7 +156,7 @@ class Repository(object): raise Exception("No such image %s version %s" % name, version) path = os.path.join(self.config.path, r[0]) debug("Getting %s v%s from %s" % (name, version, path)) - return PackageImage(path, md5name=True, verbose=self.verbose) + return PackageImage(path, md5name=True) def last(self, name): '''Return last version of name in repo or -1 if not found''' @@ -295,8 +303,7 @@ class RepositoryManager(object): This call implement a cache and a manager for multiple repositories ''' - def __init__(self, cache_path=None, timeout=None, verbose=True): - self.verbose = verbose + def __init__(self, cache_path=None, timeout=None): self.timeout = 3 if timeout is None else timeout self.repos = [] self.tempfiles = [] @@ -345,7 +352,7 @@ class RepositoryManager(object): llast = int(os.stat(filedest).st_mtime) # if repo is out of date, download it if rlast != llast: - arrow("Getting %s" % config.dbpath, 1, self.verbose) + arrow("Getting %s" % config.dbpath) istools.copy(config.dbpath, filedest, uid=config.uid, gid=config.gid, @@ -353,7 +360,7 @@ class RepositoryManager(object): timeout=self.timeout) os.utime(filedest, (rlast, rlast)) config.dbpath = filedest - self.repos.append(Repository(config, self.verbose)) + self.repos.append(Repository(config)) def get(self, name, version=None): '''Crawl all repo to get the most recent image''' diff --git a/installsystems/template.py b/installsystems/template.py index f24bd7eb40615c8aba35d0af91fbf17469afe152..2bbf81fb1f7e6c1327ff4682a5a54107ac5a55ab 100644 --- a/installsystems/template.py +++ b/installsystems/template.py @@ -17,6 +17,7 @@ parser = """# -*- python -*- import os import installsystems.argparse as argparse +from installsystems.printer import arrow class TargetAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): @@ -37,7 +38,9 @@ setup = """# -*- python -*- # image object is a reference to current image # namespace object is the persistant, it can be used to store data accross scripts -print "hostname: %s" % namespace.hostname +from installsystems.printer import arrow + +arrow("hostname: %s" % namespace.hostname) # uncomment to extract payload named root in namespace.target directory #image.payload["rootfs"].extract(namespace.target)