From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/
Date: Fri, 6 Sep 2013 17:27:43 +0000 (UTC) [thread overview]
Message-ID: <1378488268.fba66f36ad0cad176d7b024880d92d2693058800.dywi@gentoo> (raw)
commit: fba66f36ad0cad176d7b024880d92d2693058800
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Sep 6 17:24:28 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Sep 6 17:24:28 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=fba66f36
roverlay/runtime: IndependentRuntimeEnvironment
env for scripts that are independent of roverlay's core functionality.
This allows to add a setup script that handles config file creation (already
implemented as roverlay-mkconfig), config initialization (fs layout and what's
currently done by pkg_config() in the live ebuild, but more controlled)
and enabling/disabling hooks.
---
roverlay/runtime.py | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 122 insertions(+), 3 deletions(-)
diff --git a/roverlay/runtime.py b/roverlay/runtime.py
index de20f91..bbc73d7 100644
--- a/roverlay/runtime.py
+++ b/roverlay/runtime.py
@@ -14,10 +14,54 @@ import roverlay.core
import roverlay.hook
import roverlay.remote.repolist
import roverlay.stats.collector
+import roverlay.util.objects
+import roverlay.recipe.easylogger
from roverlay.core import DIE, die
-class RuntimeEnvironmentBase ( object ):
+# TODO: move/merge roverlay.core.DIE into runtime env
+
+
+class MinimalRuntimeEnvironment ( object ):
+
+ HLINE = 79 * '-'
+
+ def __init__ ( self ):
+ super ( MinimalRuntimeEnvironment, self ).__init__()
+ self.logger = None
+ self.bind_logger ( logging.getLogger() )
+ # -- end of __init__ (...) ---
+
+ def bind_logger ( self, logger ):
+ self.logger = logger
+ self.log_debug = logger.debug
+ self.log_info = logger.info
+ self.log_warn = logger.warn
+ self.log_warning = logger.warning
+ self.log_error = logger.error
+ self.log_critical = logger.critical
+ # --- end of bind_logger (...) ---
+
+ @roverlay.util.objects.abstractmethod
+ def setup ( self ):
+ pass
+
+ def die ( self, msg=None, code=None ):
+ """
+ Calls syst.exit (code:=1) after printing a message (if any).
+ """
+ code = 1 if code is None else code
+ if msg is not None:
+ sys.stderr.write ( msg + "\n" )
+# else:
+# sys.stderr.write ( "died.\n" )
+ sys.exit ( code )
+ # --- end of die (...) ---
+
+# --- end of MinimalRuntimeEnvironment ---
+
+
+class RuntimeEnvironmentBase ( MinimalRuntimeEnvironment ):
ARG_PARSER_CLS = None
KEEP_ARG_PARSER = False
@@ -28,11 +72,9 @@ class RuntimeEnvironmentBase ( object ):
config_file_name=roverlay.core.DEFAULT_CONFIG_FILE_NAME
):
super ( RuntimeEnvironmentBase, self ).__init__()
- self.logger = logging.getLogger()
self.installed = bool ( installed )
self.hide_exceptions = bool ( hide_exceptions )
self.config_file_name = str ( config_file_name )
- self.HLINE = 79 * '-'
self.stats = roverlay.stats.collector.static
self.config = None
@@ -220,3 +262,80 @@ class RuntimeEnvironment ( RuntimeEnvironmentBase ):
# --- end of optionally (...) ---
# --- end of RuntimeEnvironment ---
+
+
+class IndependentRuntimeEnvironment ( MinimalRuntimeEnvironment ):
+
+ LOG_FORMAT = None
+
+ def __init__ ( self, installed=True ):
+ super ( IndependentRuntimeEnvironment, self ).__init__()
+ self.config = roverlay.config.tree.ConfigTree ( register_static=False )
+
+ self.CONFIG_DEFAULTS = { 'installed': installed, }
+ self.extend_config ( self.CONFIG_DEFAULTS )
+
+ self.parser = None
+ self.options = None
+ self.commands = None
+ # --- end of __init__ (...) ---
+
+ def extend_config ( self, additional_config ):
+ self.config.merge_with ( additional_config )
+ # --- end of extend_config (...) ---
+
+ def reset_config ( self ):
+ self.config.reset()
+ self.extend_config ( self.CONFIG_DEFAULTS )
+ # --- end of reset_config (...) ---
+
+ def inject_config_path ( self, path, value ):
+ return self.config.inject ( path, value, suppress_log=True )
+ # --- end of inject_config_path (...) ---
+
+ @roverlay.util.objects.abstractmethod
+ def create_argparser ( self ):
+ pass
+ # --- end of create_argparser (...) ---
+
+ def setup_argparser ( self ):
+ parser = self.create_argparser()
+ if parser is not False:
+ parser.setup()
+ self.parser = parser
+
+ parser.parse()
+
+ self.options = parser.get_options()
+ self.commands = parser.get_commands()
+ # --- end of do_setup_parser (...) ---
+
+ def setup_common ( self ):
+ roverlay.recipe.easylogger.force_console_logging (
+ log_formatter=logging.Formatter ( self.LOG_FORMAT )
+ )
+ self.setup_argparser()
+ # --- end of setup_common (...) ---
+
+ def setup ( self ):
+ self.setup_common()
+ # --- end of setup (...) ---
+
+ def option ( self, key, fallback=None ):
+ return self.options.get ( key, fallback )
+ # --- end of option (...) ---
+
+ def optionally ( self, func, key, *args, **kwargs ):
+ if self.options.get ( key, False ):
+ return func ( *args, **kwargs )
+ else:
+ return None
+ # --- end of optionally (...) ---
+
+ def is_installed ( self ):
+ return self.config.get_or_fail ( 'installed' )
+ # --- end of is_installed (...) ---
+
+ installed = property ( is_installed )
+
+# --- end of IndependentRuntimeEnvironment ---
next reply other threads:[~2013-09-06 17:27 UTC|newest]
Thread overview: 159+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-06 17:27 André Erdmann [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-01-26 17:41 [gentoo-commits] proj/R_overlay:master commit in: roverlay/ André Erdmann
2015-01-26 17:41 André Erdmann
2014-07-18 16:20 André Erdmann
2014-07-18 2:50 [gentoo-commits] proj/R_overlay:wip/addition_control " André Erdmann
2014-07-18 16:20 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2014-07-18 2:28 [gentoo-commits] proj/R_overlay:wip/addition_control " André Erdmann
2014-07-18 16:20 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2014-07-16 15:14 André Erdmann
2014-06-05 22:09 André Erdmann
2014-04-01 16:38 André Erdmann
2014-02-16 16:30 André Erdmann
2014-02-15 19:49 André Erdmann
2014-02-15 19:49 André Erdmann
2014-01-25 18:14 André Erdmann
2013-12-11 18:40 André Erdmann
2013-12-11 18:40 André Erdmann
2013-09-23 15:30 André Erdmann
2013-09-20 15:57 André Erdmann
2013-09-19 15:00 André Erdmann
2013-09-17 16:40 André Erdmann
2013-09-17 16:40 André Erdmann
2013-09-17 16:40 André Erdmann
2013-09-17 16:40 André Erdmann
2013-09-16 13:43 André Erdmann
2013-09-13 15:10 André Erdmann
2013-09-12 16:36 André Erdmann
2013-09-12 16:36 André Erdmann
2013-09-12 16:36 André Erdmann
2013-09-11 11:14 André Erdmann
2013-09-11 10:19 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-06 17:27 André Erdmann
2013-09-03 15:50 André Erdmann
2013-09-02 12:27 André Erdmann
2013-09-02 8:44 André Erdmann
2013-08-30 14:49 André Erdmann
2013-08-30 14:49 André Erdmann
2013-08-29 12:36 André Erdmann
2013-08-29 12:36 André Erdmann
2013-08-28 15:54 André Erdmann
2013-08-27 15:39 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-19 15:42 André Erdmann
2013-08-16 14:05 André Erdmann
2013-08-16 11:02 André Erdmann
2013-08-16 10:43 André Erdmann
2013-08-16 10:43 André Erdmann
2013-08-14 14:56 André Erdmann
2013-08-14 14:56 André Erdmann
2013-08-13 8:56 André Erdmann
2013-08-13 8:56 André Erdmann
2013-08-13 8:56 André Erdmann
2013-08-12 8:28 André Erdmann
2013-08-12 8:18 André Erdmann
2013-08-07 16:10 André Erdmann
2013-08-02 14:30 André Erdmann
2013-08-02 10:34 André Erdmann
2013-08-02 10:34 André Erdmann
2013-08-01 12:44 André Erdmann
2013-08-01 12:44 André Erdmann
2013-07-29 14:56 André Erdmann
2013-07-29 8:55 André Erdmann
2013-07-26 13:02 André Erdmann
2013-07-23 7:51 André Erdmann
2013-07-23 7:51 André Erdmann
2013-07-19 18:00 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23 7:51 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-17 18:05 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-17 18:05 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-15 22:31 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-16 16:36 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-12 13:57 André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-19 18:58 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-22 15:24 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-19 18:58 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-19 18:59 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-13 16:34 André Erdmann
2013-06-05 18:08 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-13 16:34 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-05 18:08 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-13 16:34 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-04 21:06 André Erdmann
2013-04-25 16:44 André Erdmann
2013-04-25 16:44 André Erdmann
2013-03-05 11:27 André Erdmann
2013-02-09 20:45 André Erdmann
2013-02-05 17:48 André Erdmann
2013-02-05 17:48 André Erdmann
2013-01-30 20:16 André Erdmann
2013-01-30 20:16 André Erdmann
2013-01-28 23:54 André Erdmann
2013-01-28 23:54 André Erdmann
2013-01-28 23:54 André Erdmann
2012-10-02 10:04 André Erdmann
2012-08-20 11:16 André Erdmann
2012-08-13 18:07 André Erdmann
2012-08-09 9:26 André Erdmann
2012-08-08 23:46 André Erdmann
2012-08-08 23:46 André Erdmann
2012-08-07 8:50 André Erdmann
2012-08-02 15:14 André Erdmann
2012-08-01 7:25 André Erdmann
2012-07-31 17:51 André Erdmann
2012-07-30 8:52 André Erdmann
2012-07-30 8:52 André Erdmann
2012-07-24 16:59 [gentoo-commits] proj/R_overlay:overlay_wip " André Erdmann
2012-07-30 8:52 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2012-07-18 16:49 [gentoo-commits] proj/R_overlay:overlay_wip " André Erdmann
2012-07-30 8:52 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2012-07-16 16:15 André Erdmann
2012-07-16 16:15 André Erdmann
2012-07-16 16:15 [gentoo-commits] proj/R_overlay:depres_wip " André Erdmann
2012-07-16 16:15 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2012-07-10 17:43 André Erdmann
2012-07-09 17:19 André Erdmann
2012-07-04 18:21 André Erdmann
2012-07-04 18:21 André Erdmann
2012-07-03 17:48 André Erdmann
2012-06-28 13:29 André Erdmann
2012-06-26 15:42 André Erdmann
2012-06-25 18:19 André Erdmann
2012-06-21 16:55 André Erdmann
2012-06-20 19:03 André Erdmann
2012-06-20 19:03 André Erdmann
2012-06-18 16:27 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-12 17:17 André Erdmann
2012-06-06 19:52 André Erdmann
2012-06-06 19:52 André Erdmann
2012-06-06 19:52 André Erdmann
2012-06-05 17:30 André Erdmann
2012-06-04 19:07 André Erdmann
2012-06-04 19:07 André Erdmann
2012-06-04 15:43 André Erdmann
2012-06-01 16:19 André Erdmann
2012-06-01 16:19 André Erdmann
2012-06-01 15:46 André Erdmann
2012-05-31 18:24 André Erdmann
2012-05-30 20:15 André Erdmann
2012-05-30 19:36 André Erdmann
2012-05-30 19:36 André Erdmann
2012-05-30 16:09 André Erdmann
2012-05-30 16:09 André Erdmann
2012-05-30 16:09 André Erdmann
2012-05-30 16:09 André Erdmann
2012-05-30 10:58 André Erdmann
2012-05-30 10:58 André Erdmann
2012-05-30 10:58 André Erdmann
2012-05-30 10:58 André Erdmann
2012-05-29 17:09 André Erdmann
2012-05-29 17:09 André Erdmann
2012-05-29 17:09 André Erdmann
2012-05-29 17:09 André Erdmann
2012-05-29 17:09 André Erdmann
2012-05-26 13:14 André Erdmann
2012-05-26 13:14 André Erdmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1378488268.fba66f36ad0cad176d7b024880d92d2693058800.dywi@gentoo \
--to=dywi@mailerd.de \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox