From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: /
Date: Wed, 4 Jul 2012 18:21:10 +0000 (UTC) [thread overview]
Message-ID: <1341425978.d598dd5307b8ed3cb076ca3e97f7493f64ef1da6.dywi@gentoo> (raw)
commit: d598dd5307b8ed3cb076ca3e97f7493f64ef1da6
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jul 4 18:19:35 2012 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jul 4 18:19:38 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=d598dd53
main script
* added some options
* unique exit codes
modified: main.py
---
main.py | 174 +++++++++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 130 insertions(+), 44 deletions(-)
diff --git a/main.py b/main.py
index da56c3a..a4f2227 100755
--- a/main.py
+++ b/main.py
@@ -2,23 +2,49 @@
import sys
-# other roverlay modules will be imported later
-import roverlay
+# roverlay modules will be imported later
HIDE_EXCEPTIONS = False
-def die ( msg=None, code=1 ):
- if msg:
- sys.stderr.write ( msg + "\n" )
- sys.exit ( code )
+class DIE ( object ):
+ NOP = 0
+ ERR = 1
+ BAD_USAGE = 3
+ ARG = 9
+ CONFIG = 10
+ OV_CREATE = 20
+ SYNC = 30
+ CMD_LEFTOVER = 90
+ IMPORT = 91
+ UNKNOWN = 95
+ INTERRUPT = 130
+
+ @staticmethod
+ def die ( msg=None, code=None ):
+ code = DIE.ERR if code is None else code
+ if msg is not None:
+ sys.stderr.write ( msg + "\n" )
+# else:
+# sys.stderr.write ( "died." )
+ sys.exit ( code )
+ # --- end of die (...) ---
+
+# --- DIE: exit codes ---
+die = DIE.die
if __name__ != '__main__':
- die ( "Please don't import this script..." )
+ die ( "Please don't import this script...", DIE.BAD_USAGE )
# get args
-import roverlay.argutil
+try:
+ import roverlay.argutil
+except ImportError:
+ if HIDE_EXCEPTIONS:
+ die ( "Cannot import roverlay modules!", DIE.IMPORT )
+ else:
+ raise
COMMAND_DESCRIPTION = {
'sync' : 'sync repos',
@@ -32,15 +58,27 @@ commands, config_file, additional_config, extra_opts = \
CMD_DESC=COMMAND_DESCRIPTION,
DEFAULT_CONFIG="R-overlay.conf"
)
+
+OPTION = extra_opts.get
+
del roverlay.argutil
# -- load config
+
+try:
+ import roverlay
+except ImportError:
+ if HIDE_EXCEPTIONS:
+ die ( "Cannot import roverlay modules!", DIE.IMPORT )
+ else:
+ raise
+
try:
roverlay.load_config_file ( config_file, extraconf=additional_config )
del config_file, additional_config
except:
if HIDE_EXCEPTIONS:
- die ( "Cannot load config file %r." % config_file )
+ die ( "Cannot load config file %r." % config_file, DIE.CONFIG )
else:
raise
@@ -49,72 +87,120 @@ except:
actions = set ( filter ( lambda x : x != 'nop', commands ) )
-if 'sync' in actions and extra_opts ['nosync']:
- die ( "sync command blocked by --nosync opt." )
+if 'sync' in actions and OPTION ( 'nosync' ):
+ die ( "sync command blocked by --nosync opt.", DIE.ARG )
del commands
if not actions:
# this happens if a command is nop
- die ( "Nothing to do!", 0 )
+ die ( "Nothing to do!", DIE.NOP )
# -- import roverlay modules
-from roverlay.remote import RepoList
-from roverlay.overlay.creator import OverlayCreator
-
+try:
+ from roverlay.remote import RepoList
+ from roverlay.overlay.creator import OverlayCreator
+except ImportError:
+ if HIDE_EXCEPTIONS:
+ die ( "Cannot import roverlay modules!", DIE.IMPORT )
+ else:
+ raise
-# -- run
-actions_done = list()
-### sync / nosync
-# always run 'cause commands = {create,sync} and create implies (no)sync
+# -- run methods (and some vars)
-# set up the repo list
-repo_list = RepoList ( sync_enabled=not extra_opts ['nosync'] )
+actions_done = set()
+set_action_done = actions_done.add
-## extra_opts->distdir ... TODO
-repo_list.load()
+def optionally ( call, option, *args, **kw ):
+ if OPTION ( option ):
+ return call ( *args, **kw )
+# --- end of optionally (...) ---
-## this runs _nosync() or _sync(), depending on extra_opts->nosync
-repo_list.sync()
+#repo_list = None
+#overlay = None
+def run_sync():
+ if "sync" in actions_done: return
+ try:
+ # set up the repo list
+ global repo_list
+ repo_list = RepoList (
+ sync_enabled = not OPTION ( 'nosync' ),
+ force_distroot = OPTION ( 'force_distroot' )
+ )
+
+ ## extra_opts->distdir ... TODO
+ if 'distdirs' in extra_opts:
+ repo_list.add_distdirs ( OPTION ( 'distdirs' ) )
+ else:
+ # default repo list
+ repo_list.load()
-if 'sync' in actions:
- actions_done.append ( 'sync' )
+ ## this runs _nosync() or _sync(), depending on extra_opts->nosync
+ repo_list.sync()
-###
+ set_action_done ( "sync" )
-# run overlay creation
+ except KeyboardInterrupt:
+ die ( "Interrupted", DIE.INTERRUPT )
+ except:
+ if HIDE_EXCEPTIONS:
+ die (
+ "nosync() failed!" if OPTION ( "nosync" ) \
+ else "sync() failed!",
+ DIE.SYNC
+ )
+ else:
+ raise
+# --- end of run_sync() ---
-if 'create' in actions:
+def run_overlay_create():
+ if "create" in actions_done: return
+ #run_sync()
try:
+ global overlay
overlay = OverlayCreator()
- overlay.can_write_overlay = extra_opts ['write']
+ # explicitly allow overlay writing (FIXME: remove that in OverlayCreator)
+ overlay.can_write_overlay = OPTION ( 'write_overlay' )
repo_list.add_packages ( overlay.add_package )
- overlay.run()
-
- if extra_opts ['show']:
- overlay.show_overlay()
+ overlay.run ( close_when_done=True )
- if overlay.can_write_overlay:
- overlay.write_overlay()
+ optionally ( overlay.write_overlay, 'write_overlay' )
+ optionally ( overlay.show_overlay, 'show_overlay' )
+ if OPTION ( 'print_stats' ): print ( "\n" + overlay.stats_str() )
- # write overlay on close
- overlay.close()
-
- actions_done.append ( 'create' )
+ set_action_done ( "create" )
+ except KeyboardInterrupt:
+ die ( "Interrupted", DIE.INTERRUPT )
except:
if HIDE_EXCEPTIONS:
- die ( "Overlay creation failed.", 15 )
+ die ( "Overlay creation failed.", DIE.OV_CREATE )
else:
raise
+ finally:
+ if 'overlay' in locals() and not overlay.closed:
+ # This is important 'cause it unblocks remaining ebuild creation
+ # jobs/threads, specifically waiting EbuildJobChannels in depres.
+ # It also writes the deps_unresolved file
+ overlay.close()
+# --- end of run_overlay_create() ---
+# -- run
-if len ( actions ) != len ( actions_done ):
- die ( "Some actions (out of %r) could not be performed!" % actions, 90 )
+# always run sync 'cause commands = {create,sync} and create implies (no)sync
+run_sync()
+
+if 'create' in actions: run_overlay_create()
+
+if len ( actions ) > len ( actions_done ):
+ die (
+ "Some actions (out of %r) could not be performed!" % actions,
+ DIE.CMD_LEFTOVER
+ )
next reply other threads:[~2012-07-04 18:22 UTC|newest]
Thread overview: 146+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-04 18:21 André Erdmann [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-11-24 10:41 [gentoo-commits] proj/R_overlay:master commit in: / Benda XU
2015-11-05 5:15 Benda XU
2015-01-26 17:41 André Erdmann
2014-07-16 15:14 André Erdmann
2014-06-05 22:09 André Erdmann
2014-06-05 22:09 André Erdmann
2014-06-05 22:09 André Erdmann
2014-06-05 22:09 André Erdmann
2014-06-05 22:09 André Erdmann
2014-06-05 22:09 André Erdmann
2014-06-05 22:09 André Erdmann
2014-06-05 22:09 André Erdmann
2014-06-05 22:09 André Erdmann
2014-04-01 16:38 André Erdmann
2014-04-01 16:38 André Erdmann
2014-02-22 14:56 André Erdmann
2014-02-22 14:56 André Erdmann
2014-02-21 18:15 André Erdmann
2014-02-16 3:44 Benda XU
2014-01-25 18:14 André Erdmann
2013-12-11 18:40 André Erdmann
2013-09-23 15:30 André Erdmann
2013-09-23 15:30 André Erdmann
2013-09-23 15:30 André Erdmann
2013-09-23 15:30 André Erdmann
2013-09-18 14:00 André Erdmann
2013-09-18 14:00 André Erdmann
2013-09-16 8:56 André Erdmann
2013-09-13 15:10 André Erdmann
2013-09-12 16:36 André Erdmann
2013-09-12 8:27 André Erdmann
2013-09-12 8:27 André Erdmann
2013-09-11 14:59 André Erdmann
2013-09-11 14:59 André Erdmann
2013-09-11 10:27 André Erdmann
2013-09-11 10:19 André Erdmann
2013-09-11 10:19 André Erdmann
2013-09-04 15:36 André Erdmann
2013-08-29 15:22 André Erdmann
2013-08-16 10:58 André Erdmann
2013-08-16 10:57 André Erdmann
2013-08-16 10:53 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-12 8:18 André Erdmann
2013-08-09 10:18 André Erdmann
2013-08-05 11:44 André Erdmann
2013-08-01 12:44 André Erdmann
2013-08-01 12:44 André Erdmann
2013-07-25 13:25 André Erdmann
2013-07-23 18:34 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23 18:34 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-23 14:57 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23 14:57 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-12 17:11 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-12 17:11 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-12 14:03 André Erdmann
2013-07-11 16:44 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-11 16:29 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-11 10:36 André Erdmann
2013-07-10 16:16 André Erdmann
2013-07-10 16:16 André Erdmann
2013-07-10 15:10 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-10 16:16 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-03 10:05 André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-22 15:24 André Erdmann
2013-02-09 21:23 André Erdmann
2013-02-09 20:45 André Erdmann
2013-02-03 19:32 André Erdmann
2013-01-28 23:56 André Erdmann
2013-01-27 16:51 Denis Dupeyron
2013-01-25 23:27 Denis Dupeyron
2013-01-25 17:44 Denis Dupeyron
2013-01-09 19:15 André Erdmann
2012-08-20 10:39 André Erdmann
2012-08-20 10:39 André Erdmann
2012-08-17 17:26 André Erdmann
2012-08-10 15:16 André Erdmann
2012-08-10 15:16 André Erdmann
2012-08-10 15:16 André Erdmann
2012-08-10 15:16 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-06 19:01 André Erdmann
2012-08-03 15:04 André Erdmann
2012-08-03 15:04 André Erdmann
2012-08-03 15:04 André Erdmann
2012-08-03 15:04 André Erdmann
2012-08-03 13:59 André Erdmann
2012-08-03 13:38 André Erdmann
2012-08-03 13:38 André Erdmann
2012-08-01 21:10 André Erdmann
2012-08-01 7:38 André Erdmann
2012-07-30 15:53 André Erdmann
2012-07-30 15:53 André Erdmann
2012-07-16 16:15 André Erdmann
2012-07-11 18:43 André Erdmann
2012-07-11 18:43 André Erdmann
2012-07-10 18:03 André Erdmann
2012-07-09 17:19 André Erdmann
2012-07-09 17:19 André Erdmann
2012-07-09 17:19 André Erdmann
2012-07-09 17:19 André Erdmann
2012-07-06 22:19 André Erdmann
2012-07-06 22:19 André Erdmann
2012-07-06 8:15 André Erdmann
2012-07-05 16:01 André Erdmann
2012-07-05 16:00 André Erdmann
2012-07-04 18:21 André Erdmann
2012-07-04 18:21 André Erdmann
2012-07-03 17:48 André Erdmann
2012-07-03 17:48 André Erdmann
2012-06-29 22:48 André Erdmann
2012-06-29 22:48 André Erdmann
2012-06-27 14:46 André Erdmann
2012-06-27 14:46 André Erdmann
2012-06-26 15:42 André Erdmann
2012-06-26 15:42 André Erdmann
2012-06-25 18:19 André Erdmann
2012-06-22 18:13 André Erdmann
2012-06-22 18:13 André Erdmann
2012-06-22 18:13 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-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-13 16:34 André Erdmann
2012-06-13 16:34 André Erdmann
2012-06-12 17:17 André Erdmann
2012-06-11 18:31 André Erdmann
2012-06-11 18:31 André Erdmann
2012-06-11 18:31 André Erdmann
2012-06-08 17:48 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-01 15:46 André Erdmann
2012-06-01 15:46 André Erdmann
2012-05-31 18:24 André Erdmann
2012-05-31 18:24 André Erdmann
2012-05-30 19:36 André Erdmann
2012-05-30 16:09 André Erdmann
2012-05-30 10:58 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=1341425978.d598dd5307b8ed3cb076ca3e97f7493f64ef1da6.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