diff --git a/bin/is b/bin/is new file mode 100755 index 0000000000000000000000000000000000000000..189c4d0ad705c3a61719b70f224789861507ef7a --- /dev/null +++ b/bin/is @@ -0,0 +1,264 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Started 30/06/2011 by Seblu + +''' +InstallSystems Command line Tool +''' + +import os +import time +import datetime +import installsystems +import installsystems.argparse as argparse # To be removed when python 2.7 +import installsystems.tools as istools +from installsystems.printer import * +from installsystems.repository import Repository +from installsystems.repository import RepositoryManager +from installsystems.repository import RepositoryConfig +from installsystems.image import PackageImage, SourceImage +from installsystems.config import MainConfigFile, RepoConfigFile + +def load_repositories(args): + ''' + Load repository on arg line + ''' + # load repo configs + repos = [] + for r_config in args.repo_config: + repos += RepoConfigFile(r_config).repos + # filtering on repository name if present + if args.repo_filter is not None: + repos = filter(lambda x: x.name == args.repo_filter, repos) + return repos + +def c_init_image(args): + ''' + Create a new source image + ''' + try: + simg = SourceImage.create(args.path) + except Exception as e: + error("init image failed: %s." % e) + +def c_init_repo(args): + ''' + Create a empty repository + ''' + try: + repos = load_repositories(args) + if len(repos) != 1: + raise Exception("Please select one repository") + Repository.create(repos[0]) + debug("Repository: %s" % args[0]) + except Exception as e: + raise Exception("init repo failed: %s" % e) + +def c_build(args): + ''' + Build an image source + ''' + try: + # build start time + t0 = time.time() + # load source image + simg = SourceImage(args.path) + # do the job + simg.build(force=args.force, check=not args.no_check) + # compute building time + t1 = time.time() + dt = int(t1 - t0) + arrow("Build time: %s" % datetime.timedelta(seconds=dt)) + except Exception as e: + error("build failed: %s." % e) + +def c_add(args): + ''' + Add an image package into a repository + ''' + try: + repos = load_repositories(args) + if len(repos) != 1: + raise Exception("Please select one repository") + repo = Repository(repos[0]) + pkg = PackageImage(args.path) + repo.add(pkg) + except Exception as e: + raise Exception("add failed: %s" % e) + +def c_del(args): + ''' + Remove an image package from a repository + ''' + try: + repos = load_repositories(args) + if len(repos) != 1: + raise Exception("Please select one repository") + repo = Repository(repos[0]) + repo.delete(args.image_name, args.image_version) + except Exception as e: + raise Exception("del failed: %s" % e) + +def c_install(args): + ''' + Install an image + ''' + # looks if arguments is a file or image name + if istools.pathtype(args.image) == "file" and os.path.isfile(args.image): + pkg = PackageImage(istools.abspath(args.image)) + elif PackageImage.check_image_name(args.image): + # remove cache is asked + if args.no_cache: + config.cache = None + # init repo cache object + repoman = RepositoryManager(config.cache, timeout=args.timeout) + # register command line repositories (order matter) + for rpath in args.repo_path: + repoman.register(RepositoryConfig(None, path=rpath)) + # register config repositories + for r_config in args.repo_config: + for r_repo in RepoConfigFile(r_config).repos: + repoman.register(r_repo) + # get image package + pkg = repoman.get(args.image, args.image_version) + else: + args.subparser.print_usage() + exit(1) + # Print setup information + arrow("Installing %s v%s" % (pkg.name, pkg.version)) + # install start time + t0 = time.time() + # run parser scripts with parser parser argument + pkg.run_parser(parser=args.subparser) + # call parser again, with extended attributes + arrow("Parsing arguments") + args = args.parser.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)) + +def c_search(args): + ''' + Search in repository + ''' + raise NotImplementedError("Not yet implemented") + +def c_get(args): + ''' + Get a remove image in current directory + ''' + raise NotImplementedError("Not yet implemented") + +def c_clean(args): + ''' + Clean a repository + ''' + raise NotImplementedError("Not yet implemented") + + +# Top level argument parsing +p_main = argparse.ArgumentParser() +p_main.add_argument("-V", "--version", action="version", + version=installsystems.version, + help="show installsystems version") +# exclusive group on debug/quiet +ex_group = p_main.add_mutually_exclusive_group() +ex_group.add_argument('-d', "--debug", action="store_true", + help="active debug mode") +ex_group.add_argument('-q', "--quiet", action="store_true", + help="active quiet mode") +# common options +p_main.add_argument("-c", "--config", default="is", + help="config file path") +p_main.add_argument("-f", "--repo-filter", default=None, + help="select repository by name in config files") +p_main.add_argument("-r", "--repo-path", action="append", default=[], + help="repository path") +p_main.add_argument("-R", "--repo-config", action="append", + default=["repository"], + help="repository config (can be specified more than one time)") +p_main.add_argument("-t", "--timeout", dest="timeout", type=int, default=None, + help="download timeout") +# create a subparsers for each command +subparsers = p_main.add_subparsers() + +# init command parser +p_init = subparsers.add_parser("init", help="initialize source image or repository") +sp_init = p_init.add_subparsers() +p_init_repo = sp_init.add_parser("repo", help=c_init_repo.__doc__.lower()) +p_init_repo.add_argument("repo_filter", nargs="?", default=argparse.SUPPRESS, + help="Name or path of a repository to init") +p_init_repo.set_defaults(func=c_init_repo) +p_init_image = sp_init.add_parser("image", help=c_init_image.__doc__.lower()) +p_init_image.add_argument("path", help="Path of new image directory") +p_init_image.set_defaults(func=c_init_image) + +# build command parser +p_build = subparsers.add_parser("build", help=c_build.__doc__.lower()) +p_build.add_argument('-f', "--force", action="store_true", default=False, + help="overwrite existing image") +p_build.add_argument('-c', "--no-check", action="store_true", default=False, + help="do not check compilation before adding scripts") +p_build.add_argument("path", nargs="?", default=".") +p_build.set_defaults(func=c_build) + +# add command parser +p_add = subparsers.add_parser("add", help=c_add.__doc__.lower()) +p_add.add_argument("path") +p_add.set_defaults(func=c_add) + +# del command parser +p_del = subparsers.add_parser("del", help=c_del.__doc__.lower()) +p_del.add_argument("image_name") +p_del.add_argument("image_version") +p_del.set_defaults(func=c_del) + +# install command parser +p_install = subparsers.add_parser("install", help=c_install.__doc__.lower()) +p_install.add_argument('-f', "--force", action="store_true", default=False, + help="overwrite existing image") +p_install.add_argument("-c", "--cache", default=None, + help="Not use persistent db caching") +p_install.add_argument("--no-cache", action="store_true", default=False, + help="Not use persistent db caching") +p_install.add_argument("-v", "--image-version", type=int, default=None, + help="image version") +p_install.add_argument("image", help="image to install (path or name)") +p_install.set_defaults(func=c_install, parser=p_main, subparser=p_install) + +# get command parser +p_get = subparsers.add_parser("get", help=c_get.__doc__.lower()) +p_get.set_defaults(func=c_get) + +# search command parser +p_search = subparsers.add_parser("search", help=c_search.__doc__.lower()) +p_search.set_defaults(func=c_search) + +# clean command parser +p_clean = subparsers.add_parser("clean", help=c_clean.__doc__.lower()) +p_clean.set_defaults(func=c_clean) + +try: + # Parse and run + args = p_main.parse_known_args()[0] + # set debug and quiet mode before merge + installsystems.debug = args.debug + installsystems.quiet = args.quiet + # load isinstall config + config = MainConfigFile(args.config) + config.merge(args) + # set debug and quiet mode after merge + installsystems.debug = args.debug + installsystems.quiet = args.quiet + if not hasattr(args, "parser"): + args = p_main.parse_args(namespace=args) + # let's go + args.func(args) +except Exception as e: + p_main.print_usage() + error(e) +except KeyboardInterrupt: + warn("Keyboard Interrupted") diff --git a/bin/isimage b/bin/isimage deleted file mode 100755 index fe55cd3e1a2d18e9bcc9c834a92453e49b70cf99..0000000000000000000000000000000000000000 --- a/bin/isimage +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Started 10/05/2011 by Seblu - -''' -InstallSystems Image Manipulation Tool -''' - -import os -import time -import datetime -import installsystems -import installsystems.argparse as argparse # To be removed when python 2.7 -from installsystems.printer import * -from installsystems.image import SourceImage - -def init(args): - '''Create an empty fresh source image tree''' - # call init from library - try: - simg = SourceImage.create(args.path) - except Exception as e: - error("init failed: %s." % e) - -def build(args): - '''Create a package image''' - try: - # build start time - t0 = time.time() - # load source image - simg = SourceImage(args.path) - # do the job - simg.build(force=args.force, check=args.check) - # compute building time - t1 = time.time() - dt = int(t1 - t0) - arrow("Build time: %s" % datetime.timedelta(seconds=dt)) - except Exception as e: - error("build failed: %s." % e) - -# Top level argument parsing -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="store_true", - help="active debug mode") -p_main.add_argument('-q', "--quiet", action="store_true", - help="active quiet mode") - -subparsers = p_main.add_subparsers() -# Init command parser -p_init = subparsers.add_parser("init", help = init.__doc__.lower()) -p_init.add_argument("path", help = "Path of new image directory") -p_init.set_defaults(func = init) -# Build command parser -p_build = subparsers.add_parser("build", help = build.__doc__.lower()) -p_build.add_argument('-f', "--force", action = "store_true", dest = "force", default = False, - help = "overwrite existing image") -p_build.add_argument('-c', "--no-check", action = "store_false", dest = "check", default = True, - help = "do not check compilation before adding scripts") - -p_build.add_argument("path", nargs = "?", default = ".") -p_build.set_defaults(func = build) -# Parse and run -args = p_main.parse_args() -# set debug and quiet mode -installsystems.debug = args.debug -installsystems.quiet = args.quiet -# exectue subparser functions -args.func(args) diff --git a/bin/isinstall b/bin/isinstall deleted file mode 100755 index c8ee23f5fe4dfa4cd1e86fa64e1d36385b1a7ace..0000000000000000000000000000000000000000 --- a/bin/isinstall +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Started 18/05/2011 by Seblu - -''' -InstallSystems Installation Tool -''' - -import os -import time -import datetime -import installsystems -import installsystems.tools as istools -import installsystems.argparse as argparse # To remove when default to python 2.7 -from installsystems.printer import * -from installsystems.repository import RepositoryManager, RepositoryConfig -from installsystems.image import PackageImage -from installsystems.config import MainConfigFile, RepoConfigFile - -# 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="store_true", - help="active debug mode") -p_main.add_argument('-q', "--quiet", action="store_true", - help="active quiet mode") -p_main.add_argument("--no-cache", action = "store_false", default = False, - help = "Not use persistent db caching") -p_main.add_argument("-c", "--config", dest = "config", default = "isinstall", - help = "config file path") -p_main.add_argument("-v", "--image-version", type = int, default = None, - help = "image version") -p_main.add_argument("-t", "--timeout", dest = "timeout", type = int, default = None, - help = "download timeout") -p_main.add_argument("-r", "--repo-path", action = "append", default = [], - help = "repository path") -p_main.add_argument("-R", "--repo-config", action = "append", default = ["repository"], - help = "repository config path (can be specified more than one time)") -p_main.add_argument("image_name", help = "image to install (path or name)") - -try: - # Partial parse - args = p_main.parse_known_args()[0] - # load main config - config = MainConfigFile(args.config) - config.merge(args) - # set debug and quiet mode after merge - installsystems.debug = args.debug - installsystems.quiet = args.quiet - # looks if arguments is a file or image name - if istools.pathtype(args.image_name) == "file" and os.path.isfile(args.image_name): - pkg = PackageImage(istools.abspath(args.image_name)) - elif PackageImage.check_image_name(args.image_name): - # remove cache is asked - if args.no_cache: - config.cache = None - # init repo cache object - repoman = RepositoryManager(config.cache, timeout=args.timeout) - # register command line repositories (order matter) - for rpath in args.repo_path: - repoman.register(RepositoryConfig(None, path=rpath)) - # register config repositories - for r_config in args.repo_config: - for r_repo in RepoConfigFile(r_config).repos: - repoman.register(r_repo) - # get image package - pkg = repoman.get(args.image_name, args.image_version) - else: - p_main.print_usage() - exit(1) - # Print setup information - arrow("Installing %s v%s" % (pkg.name, pkg.version)) - # install start time - t0 = time.time() - # run parser scripts with parser parser argument - pkg.run_parser(parser=p_main) - # call parser again, with extended attributes - 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)) -except Exception as e: - error(e) -except KeyboardInterrupt: - warn("Keyboard Interrupted") diff --git a/bin/isrepo b/bin/isrepo deleted file mode 100755 index 23abde3e587b3f4e8d9d683e2a02cab0f706e9b1..0000000000000000000000000000000000000000 --- a/bin/isrepo +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Started 16/05/2011 by Seblu - -''' -InstallSystems Repository Manipulation Tool -''' - -import os -import installsystems -import installsystems.argparse as argparse # To be removed when python 2.7 -from installsystems.printer import * -from installsystems.repository import Repository, RepositoryConfig -from installsystems.image import PackageImage -from installsystems.config import MainConfigFile, RepoConfigFile - -def init(args): - ''' - Create an empty fresh repo tree - ''' - # call init from library - try: - 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) - pkg = PackageImage(args.path) - repo.add(pkg) - except Exception as e: - raise Exception("add failed: %s" % e) - -def delete(args): - ''' - Remove a package from repository - ''' - try: - repo = Repository(args.repository) - repo.delete(args.image_name, args.image_version) - except Exception as e: - raise Exception("del failed: %s" % e) - -# Top level argument parsing -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="store_true", - help="active debug mode") -p_main.add_argument('-q', "--quiet", action="store_true", - help="active quiet mode") -p_main.add_argument("-c", "--config", default="isrepo", - help="config file path") -p_main.add_argument("-r", "--repo-name", default=None, - help="select repository by name in config files") -p_main.add_argument("-R", "--repo-config", action="append", - default=["repository"], - help="repository config (can be specified more than one time)") -subparsers = p_main.add_subparsers() -# Init command parser -p_init = subparsers.add_parser("init", help = init.__doc__.lower()) -p_init.set_defaults(func = init) -# Add command parser -p_add = subparsers.add_parser("add", help = add.__doc__.lower()) -p_add.add_argument("path") -p_add.set_defaults(func = add) -# Del command parser -p_del = subparsers.add_parser("del", help = delete.__doc__.lower()) -p_del.add_argument("image_name") -p_del.add_argument("image_version") -p_del.set_defaults(func = delete) -try: - # Parse and run - args = p_main.parse_args() - # load isinstall config - config = MainConfigFile(args.config) - config.merge(args) - # set debug and quiet mode after merge - installsystems.debug = args.debug - installsystems.quiet = args.quiet - # load repo configs - repos = [] - for r_config in args.repo_config: - repos += RepoConfigFile(r_config).repos - # filtering on repository name if present - if args.repo_name is not None: - repos = filter(lambda x: x.name == args.repo_name, repos) - if len(repos) == 1: - args.repository = repos[0] - elif len(repos) > 1: - raise Exception("Please select a repository with -r") - if len(repos) == 0 or not isinstance(args.repository, RepositoryConfig): - raise Exception("No image repository found") - debug("Repository: %s" % args.repository.path) - args.func(args) -except Exception as e: - p_main.print_usage() - error(e) -except KeyboardInterrupt: - warn("Keyboard Interrupted") diff --git a/debian/control b/debian/control index 0d8f772bc2cfb3c1e6e98d34bb2d8cb5a20f2057..aff7adf31151b843327d9722bc512f010c496783 100644 --- a/debian/control +++ b/debian/control @@ -6,26 +6,12 @@ Build-Depends: debhelper (>= 7), python-central (>= 0.6), cdbs (>= 0.4.50), pyt XS-Python-Version: >= 2.6 Standards-Version: 3.9.1 -Package: isinstall +Package: installsystems Architecture: all Depends: ${misc:Depends}, ${python:Depends}, python-installsystems XB-Python-Version: ${python:Versions} Description: InstallSytems Installer - isinstall is a tool to install image from InstallSystems images - -Package: isimage -Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, python-installsystems -XB-Python-Version: ${python:Versions} -Description: InstallSystems Image Tools - isimage is a tool to create and manage InstallSystems images - -Package: isrepo -Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, python-installsystems -XB-Python-Version: ${python:Versions} -Description: InstallSystems Repository Tools - isrepo is a tool to manage InstallSystems repositories + InstallSystems command line tool Package: python-installsystems Architecture: all diff --git a/debian/installsystems.install b/debian/installsystems.install new file mode 100644 index 0000000000000000000000000000000000000000..bf89e992f851a9789f7a38df12545852a880dba6 --- /dev/null +++ b/debian/installsystems.install @@ -0,0 +1 @@ +usr/bin/is diff --git a/debian/isimage.install b/debian/isimage.install deleted file mode 100644 index 2022c11bdc0d46dcd7939f7ea4c97a4465c8510c..0000000000000000000000000000000000000000 --- a/debian/isimage.install +++ /dev/null @@ -1 +0,0 @@ -usr/bin/isimage diff --git a/debian/isinstall.install b/debian/isinstall.install deleted file mode 100644 index ab957bc1dd2323d37dac471c174e3900e370d7ce..0000000000000000000000000000000000000000 --- a/debian/isinstall.install +++ /dev/null @@ -1 +0,0 @@ -usr/bin/isinstall diff --git a/debian/isrepo.install b/debian/isrepo.install deleted file mode 100644 index 59c93da27820003d977bcda41068dbe9350fc3cf..0000000000000000000000000000000000000000 --- a/debian/isrepo.install +++ /dev/null @@ -1 +0,0 @@ -usr/bin/isrepo diff --git a/debian/rules b/debian/rules index 14ed5aee326234c17b2b19c6ba248df7858bc185..3049f4262b5891a60b909271ee803aff0a7449bf 100755 --- a/debian/rules +++ b/debian/rules @@ -9,7 +9,7 @@ include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/python-distutils.mk -PYTHON_PACKAGES := isinstall isimage isrepo python-installsystems +PYTHON_PACKAGES := is python-installsystems $(patsubst %,binary-install/%,$(PYTHON_PACKAGES)) :: dh_pycentral -p$(cdbs_curpkg) diff --git a/installsystems/config.py b/installsystems/config.py index 875a30040e07fcb6424b474d34658e9abf342644..ff937998ea3a21648835cf1ff33987e7dc7ba587 100644 --- a/installsystems/config.py +++ b/installsystems/config.py @@ -62,7 +62,7 @@ class MainConfigFile(ConfigFile): self._config = {} # loading config file if exists if self.path is None: - debug("No %s.conf file to load" % self.prefix) + debug("No main config file to load") return debug("Loading config file: %s" % self.path) try: diff --git a/installsystems/repository.py b/installsystems/repository.py index 1322e8fba32c8e0caa03f79be6fc4f1d97a17557..0eaf5fb7c0c278a0aadd0e9fd6ee7cf45c1bcf71 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -417,6 +417,7 @@ class RepositoryManager(object): if not os.path.exists(filedest): open(filedest, "wb") # get remote last value + print config.lastpath rlast = int(istools.uopen(config.lastpath).read().strip()) # get local last value llast = int(os.stat(filedest).st_mtime) diff --git a/samples/is.conf b/samples/is.conf new file mode 100644 index 0000000000000000000000000000000000000000..23b9b6f466e0e15bfa8749c04e7e1ab8c99333bd --- /dev/null +++ b/samples/is.conf @@ -0,0 +1,27 @@ +# is program configuration + +[is] + +# Set debug mode +#debug = True + +# Set quiet mode +#quiet = True + +# define a custom cache directory +#cache = /tmp/sex + +# disable cache of remote repository +#no_cache = 1 + +# disable check of script during build +#no_check = 1 + +# define connection timeout +#timeout = 30 + +# default repository name +#repo_filter = local + +# custom repository config file +#repo_config = diff --git a/samples/isinstall.conf b/samples/isinstall.conf deleted file mode 100644 index 188337ce0d9133b46ecfcd9c4e1c6312b98022c3..0000000000000000000000000000000000000000 --- a/samples/isinstall.conf +++ /dev/null @@ -1,14 +0,0 @@ -# isinstall program configuration - -[isinstall] -# define a custom cache directory -#cache = /tmp/sex - -# disable cache of remote repository -#no_cache = 1 - -# define connection timeout -#timeout = 30 - -# custom repository config file -#repo_config = diff --git a/samples/isrepo.conf b/samples/isrepo.conf deleted file mode 100644 index 9b213b21dc5c0a8ba67f4368294bb8f9ff16bf1f..0000000000000000000000000000000000000000 --- a/samples/isrepo.conf +++ /dev/null @@ -1,6 +0,0 @@ -[isrepo] -#default repository name -repo_name = local - -# custom repository config file -#repo_config = diff --git a/setup.py b/setup.py index 6de4841fb8f499ba56675e61dc9081079ceb1f6e..65b2feb9a4727b17f2c403f24d863ce44a0d2e3c 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( author_email='sebastien.luttringer@smartjog.com', license='GPL2', packages=[ 'installsystems' ], - scripts=['bin/isrepo', 'bin/isinstall', 'bin/isimage'], + scripts=[ 'bin/is' ], classifiers=[ 'Operating System :: Unix', 'Programming Language :: Python',