From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.77) (envelope-from ) id 1SmUDH-0006AH-KT for garchives@archives.gentoo.org; Wed, 04 Jul 2012 18:22:07 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id ACF4AE0693; Wed, 4 Jul 2012 18:21:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 6F979E0693 for ; Wed, 4 Jul 2012 18:21:15 +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 9BCBC1B40D0 for ; Wed, 4 Jul 2012 18:21:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 8B234E544C for ; Wed, 4 Jul 2012 18:21:10 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1341425978.d598dd5307b8ed3cb076ca3e97f7493f64ef1da6.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: / X-VCS-Repository: proj/R_overlay X-VCS-Files: main.py X-VCS-Directories: / X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: d598dd5307b8ed3cb076ca3e97f7493f64ef1da6 X-VCS-Branch: master Date: Wed, 4 Jul 2012 18:21:10 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: f007afe5-3716-4b1f-8c43-533e9d6edd31 X-Archives-Hash: a713757c886007929360bd606f8b1e3b commit: d598dd5307b8ed3cb076ca3e97f7493f64ef1da6 Author: Andr=C3=A9 Erdmann mailerd de> AuthorDate: Wed Jul 4 18:19:35 2012 +0000 Commit: Andr=C3=A9 Erdmann mailerd de> CommitDate: Wed Jul 4 18:19:38 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/R_overlay.git= ;a=3Dcommit;h=3Dd598dd53 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 @@ =20 import sys =20 -# other roverlay modules will be imported later -import roverlay +# roverlay modules will be imported later =20 HIDE_EXCEPTIONS =3D False =20 -def die ( msg=3DNone, code=3D1 ): - if msg: - sys.stderr.write ( msg + "\n" ) - sys.exit ( code ) +class DIE ( object ): + NOP =3D 0 + ERR =3D 1 + BAD_USAGE =3D 3 + ARG =3D 9 + CONFIG =3D 10 + OV_CREATE =3D 20 + SYNC =3D 30 + CMD_LEFTOVER =3D 90 + IMPORT =3D 91 + UNKNOWN =3D 95 + INTERRUPT =3D 130 + + @staticmethod + def die ( msg=3DNone, code=3DNone ): + code =3D 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 =3D DIE.die =20 =20 if __name__ !=3D '__main__': - die ( "Please don't import this script..." ) + die ( "Please don't import this script...", DIE.BAD_USAGE ) =20 =20 # get args -import roverlay.argutil +try: + import roverlay.argutil +except ImportError: + if HIDE_EXCEPTIONS: + die ( "Cannot import roverlay modules!", DIE.IMPORT ) + else: + raise =20 COMMAND_DESCRIPTION =3D { 'sync' : 'sync repos', @@ -32,15 +58,27 @@ commands, config_file, additional_config, extra_opts = =3D \ CMD_DESC=3DCOMMAND_DESCRIPTION, DEFAULT_CONFIG=3D"R-overlay.conf" ) + +OPTION =3D extra_opts.get + del roverlay.argutil =20 # -- 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=3Dadditional_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 =20 @@ -49,72 +87,120 @@ except: =20 actions =3D set ( filter ( lambda x : x !=3D 'nop', commands ) ) =20 -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 ) =20 del commands =20 =20 if not actions: # this happens if a command is nop - die ( "Nothing to do!", 0 ) + die ( "Nothing to do!", DIE.NOP ) =20 =20 # -- import roverlay modules =20 -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 =20 -# -- run =20 -actions_done =3D list() =20 -### sync / nosync -# always run 'cause commands =3D {create,sync} and create implies (no)sy= nc +# -- run methods (and some vars) =20 -# set up the repo list -repo_list =3D RepoList ( sync_enabled=3Dnot extra_opts ['nosync'] ) +actions_done =3D set() +set_action_done =3D actions_done.add =20 -## extra_opts->distdir ... TODO -repo_list.load() +def optionally ( call, option, *args, **kw ): + if OPTION ( option ): + return call ( *args, **kw ) +# --- end of optionally (...) --- =20 -## this runs _nosync() or _sync(), depending on extra_opts->nosync -repo_list.sync() +#repo_list =3D None +#overlay =3D None +def run_sync(): + if "sync" in actions_done: return + try: + # set up the repo list + global repo_list + repo_list =3D RepoList ( + sync_enabled =3D not OPTION ( 'nosync' ), + force_distroot =3D 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() =20 -if 'sync' in actions: - actions_done.append ( 'sync' ) + ## this runs _nosync() or _sync(), depending on extra_opts->nosync + repo_list.sync() =20 -### + set_action_done ( "sync" ) =20 -# 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() --- =20 -if 'create' in actions: +def run_overlay_create(): + if "create" in actions_done: return + #run_sync() try: + global overlay overlay =3D OverlayCreator() - overlay.can_write_overlay =3D extra_opts ['write'] + # explicitly allow overlay writing (FIXME: remove that in OverlayCreat= or) + overlay.can_write_overlay =3D OPTION ( 'write_overlay' ) =20 repo_list.add_packages ( overlay.add_package ) =20 - overlay.run() - - if extra_opts ['show']: - overlay.show_overlay() + overlay.run ( close_when_done=3DTrue ) =20 - 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() ) =20 - # write overlay on close - overlay.close() - - actions_done.append ( 'create' ) + set_action_done ( "create" ) =20 + 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() --- =20 +# -- run =20 -if len ( actions ) !=3D len ( actions_done ): - die ( "Some actions (out of %r) could not be performed!" % actions, 90 = ) +# always run sync 'cause commands =3D {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 + )