From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id A25CB1381F3 for ; Fri, 13 Sep 2013 15:10:50 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E207AE0BEF; Fri, 13 Sep 2013 15:10:48 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 07BDDE0BEF for ; Fri, 13 Sep 2013 15:10:47 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E0BC333ECC0 for ; Fri, 13 Sep 2013 15:10:46 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id C4637E546B for ; Fri, 13 Sep 2013 15:10:44 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1379084627.0a3962d2d7d9f9ede5316058ec9709c825223e26.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/setupscript/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/setupscript/initenv.py roverlay/setupscript/runtime.py X-VCS-Directories: roverlay/setupscript/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 0a3962d2d7d9f9ede5316058ec9709c825223e26 X-VCS-Branch: master Date: Fri, 13 Sep 2013 15:10:44 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: dd6a8995-d661-4f00-9c37-ae686cf9d899 X-Archives-Hash: bab1b1b3b9a3e95dd65dfdc29fe4fb32 commit: 0a3962d2d7d9f9ede5316058ec9709c825223e26 Author: André Erdmann mailerd de> AuthorDate: Fri Sep 13 15:03:47 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Fri Sep 13 15:03:47 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=0a3962d2 setupscript: support standalone roverlay This commit adds support for using roverlay-setup with not-installed versions of roverlay. For roverlay/setupscript/, this mostly affects the arg parser's defaults, and allows to make paths in the config file relative to the git repo (IFF a subdir). Additionally, --import-config gets disabled if roverlay is not installed. --- roverlay/setupscript/initenv.py | 21 ++++++++++- roverlay/setupscript/runtime.py | 81 +++++++++++++++++++++++++++++++++-------- 2 files changed, 84 insertions(+), 18 deletions(-) diff --git a/roverlay/setupscript/initenv.py b/roverlay/setupscript/initenv.py index 5e511f8..2807841 100644 --- a/roverlay/setupscript/initenv.py +++ b/roverlay/setupscript/initenv.py @@ -90,15 +90,24 @@ class SetupInitEnvironment ( yield ( "user\'s config root", get_path_option ( 'private_conf_root', self.setup_env.user_conf_root ) ) + yield ( "additions dir", + get_path_option ( 'additions_dir', self.setup_env.additions_dir ) + ) import_config = get_option ( 'import_config' ) if import_config == 'disable': yield ( "import config", "no" ) - else: + elif self.setup_env.is_installed(): yield ( "import config", "yes, " + self.IMPORT_CONFIG_DESC [import_config].format ( **fmt_vars ) ) + else: + yield ( + "import config", + 'no, standalone roverlay cannot import config ' + 'with mode={!r}'.format ( import_config ) + ) yield ( "enable default hooks", get_option ( 'want_default_hooks' ) ) @@ -147,7 +156,15 @@ class SetupInitEnvironment ( def do_import_config ( self, pretend ): """Imports the config.""" - mode = self.setup_env.options ['import_config'] + mode = self.setup_env.options ['import_config'] + + if mode == 'disable': + self.info ( "config import: disabled.\n" ) + return + elif not self.setup_env.is_installed(): + self.error ( "config import: disabled due to standalone mode.\n" ) + return + fs_ops = self.setup_env.private_dir user_conf_root = self.setup_env.get_user_config_root() # assert os.path.isdir ( os.path.dirname(user_conf_root) == work_root ) diff --git a/roverlay/setupscript/runtime.py b/roverlay/setupscript/runtime.py index 5a55515..43733a3 100644 --- a/roverlay/setupscript/runtime.py +++ b/roverlay/setupscript/runtime.py @@ -129,6 +129,15 @@ class SetupArgParser ( roverlay.argparser.RoverlayArgumentParser ): help="additional variables", ) + arg ( + '--prjroot-relpath', dest='prjroot_relpath', + flags=self.ARG_WITH_DEFAULT|self.ARG_OPT_IN, + help=( + 'make --{work,data,conf}-root, --{conf,additions}-dir ' + 'relative to ROVERLAY_PRJROOT (for distributing config files)' + ) + ) + return arg # --- end of setup_config (...) --- @@ -141,9 +150,9 @@ class SetupArgParser ( roverlay.argparser.RoverlayArgumentParser ): '\'--variable ADDITIONS_DIR={0}\'.'.format ( val ) ) - self.parsed ['config_vars'].append ( - "ADDITIONS_DIR=" + self.parsed ['additions_dir'] - ) +## self.parsed ['config_vars'].append ( +## "ADDITIONS_DIR=" + self.parsed ['additions_dir'] +## ) # --- end of parse_config (...) --- def setup_init ( self ): @@ -274,19 +283,39 @@ class SetupEnvironment ( roverlay.runtime.IndependentRuntimeEnvironment ): # ) # --- end of __init__ (...) --- - def create_argparser ( self ): - instinfo = self.access_constant ( 'INSTALLINFO' ) - - return SetupArgParser ( - description = 'roverlay setup script', - defaults = { + def get_parser_defaults ( self ): + if self.is_installed(): + instinfo = self.INSTALLINFO + return { 'work_root' : instinfo ['workroot'], 'data_root' : instinfo ['libexec'], 'conf_root' : instinfo ['confroot'], 'private_conf_root' : instinfo ['workroot'] + os.sep + 'config', 'import_config' : 'symlink=root', 'additions_dir' : instinfo ['workroot'] + os.sep + 'files', - }, + } + else: + assert self.prjroot + prjroot = self.prjroot + os.sep + return { + 'work_root' : prjroot + 'workdir', + 'data_root' : prjroot + 'files', + 'conf_root' : prjroot + 'config', + 'private_conf_root' : prjroot + 'config', + 'import_config' : 'disable', + 'additions_dir' : prjroot + 'files', + } + # --- end of get_parser_defaults (...) --- + + def create_argparser ( self ): + return SetupArgParser ( + description = 'roverlay setup script', + defaults = self.get_parser_defaults(), + epilog = ( + 'Environment variables:\n' + '* ROVERLAY_PRJROOT - path to roverlay\'s source dir\n' + '* ROVERLAY_INSTALLED - mark roverlay as installed (if set and not empty)\n' + ) ) # --- end of create_argparser (...) --- @@ -324,24 +353,44 @@ class SetupEnvironment ( roverlay.runtime.IndependentRuntimeEnvironment ): # --- end of _expanduser_pwd (...) --- def create_config_file ( self, expand_user=False ): + def _get_prjroot_relpath ( fspath ): + p = os.path.relpath ( fspath, self.prjroot ) + if p and ( p[0] != '.' or p == '.' ): + return p + else: + return fspath + # --- end of get_prjroot_relpath (...) --- + + get_prjroot_relpath = ( + _get_prjroot_relpath + if ( self.options ['prjroot_relpath'] and self.prjroot ) + else (lambda p: p) + ) + conf_creator = roverlay.config.defconfig.RoverlayConfigCreation ( - is_installed = self.is_installed(), - work_root = ( + is_installed = self.is_installed(), + work_root = get_prjroot_relpath ( self.work_root if expand_user else self.options ['work_root'] ), - data_root = ( + data_root = get_prjroot_relpath ( self.data_root if expand_user else self.options ['data_root'] ), - conf_root = ( + conf_root = get_prjroot_relpath ( self.user_conf_root if expand_user else self.options ['private_conf_root'] ), + additions_dir = get_prjroot_relpath ( + self.additions_dir if expand_user + else self.options ['additions_dir'] + ) ) for kv in self.options ['config_vars']: key, sepa, value = kv.partition ( '=' ) if not sepa: raise Exception ( "bad variable given: {!r}".format ( kv ) ) + elif key in { 'ADDITIONS_DIR', 'OVERLAY_ADDITIONS_DIR', }: + conf_creator.set_option ( key, get_prjroot_relpath ( value ) ) else: conf_creator.set_option ( key, value ) @@ -367,8 +416,7 @@ class SetupEnvironment ( roverlay.runtime.IndependentRuntimeEnvironment ): # --- end of auto_reconfigure (...) --- def setup ( self ): - self.PWD_INITIAL = os.getcwd() - self.setup_common() + self.setup_common ( allow_prjroot_missing=False ) # ref options = self.options @@ -389,6 +437,7 @@ class SetupEnvironment ( roverlay.runtime.IndependentRuntimeEnvironment ): self.data_root = expanduser ( options ['data_root'] ) self.conf_root = expanduser ( options ['conf_root'] ) self.user_conf_root = expanduser ( options ['private_conf_root'] ) + self.additions_dir = expanduser ( options ['additions_dir'] ) self.hook_overwrite = ( roverlay.setupscript.hookenv.HookOverwriteControl.from_str ( options ['hook_overwrite']