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 C8B3713894A for ; Sat, 9 Feb 2013 20:45:38 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C2D1721C044; Sat, 9 Feb 2013 20:45:34 +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 DDE2E21C036 for ; Sat, 9 Feb 2013 20:45:33 +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 B5BF933E3B9 for ; Sat, 9 Feb 2013 20:45:32 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 4FD39E4098 for ; Sat, 9 Feb 2013 20:45:30 +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: <1360440495.2430edacd56761c7bb4d3bfc846c5b00054a53b1.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: /, roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay.py roverlay/main.py X-VCS-Directories: / roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 2430edacd56761c7bb4d3bfc846c5b00054a53b1 X-VCS-Branch: master Date: Sat, 9 Feb 2013 20:45:30 +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: e568e2b9-9b87-42b8-a009-c63d7c95a027 X-Archives-Hash: f12f96e79a303d2305c5d9985333fa07 commit: 2430edacd56761c7bb4d3bfc846c5b00054a53b1 Author: André Erdmann mailerd de> AuthorDate: Sat Feb 9 19:31:37 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Sat Feb 9 20:08:15 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=2430edac move roverlay.py to roverlay/main.py The roverlay main() function is now part of the roverlay modules, which allows byte-compiling. --- roverlay.py | 338 +-------------------------------------- roverlay.py => roverlay/main.py | 73 +++++---- 2 files changed, 48 insertions(+), 363 deletions(-) diff --git a/roverlay.py b/roverlay.py index d18a987..31858a1 100755 --- a/roverlay.py +++ b/roverlay.py @@ -5,339 +5,11 @@ # Distributed under the terms of the GNU General Public License; # either version 2 of the License, or (at your option) any later version. -"""main script for R overlay creation""" +import roverlay.main -__all__ = [ 'DIE', 'roverlay_main' ] - -import os -import sys - -# roverlay modules will be imported later - -ROVERLAY_INSTALLED = False -HIDE_EXCEPTIONS = False -CONFIG_FILE_NAME = "R-overlay.conf" - -if ROVERLAY_INSTALLED: - # directories where the config file could be found, in order: - # * ${PWD} - # * user roverlay dir (${HOME}/roverlay) - # * system config dir /etc/roverlay - CONFIG_DIRS = tuple (( - '.', - ( - ( os.getenv ( 'HOME' ) or os.path.expanduser ( '~' ) ) - + os.sep + 'roverlay' - ), - # os.sep is '/' if /etc exists, so don't care about that - '/etc/roverlay', - )) - - - -class DIE ( object ): - """Container class for various system exit 'events'.""" - NOP = os.EX_OK - ERR = 1 - BAD_USAGE = os.EX_USAGE - USAGE = os.EX_USAGE - ARG = 9 - CONFIG = os.EX_CONFIG - OV_CREATE = 20 - SYNC = 30 - CMD_LEFTOVER = 90 - IMPORT = 91 - UNKNOWN = 95 - INTERRUPT = 130 - - @staticmethod - def die ( msg=None, code=None ): - """ - Calls syst.exit (code:=DIE.ERR) after printing a message (if any). - """ - code = DIE.ERR 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 (...) --- - -# --- DIE: exit codes --- -die = DIE.die - -def roverlay_main(): - """roverlay.py main() - parse args, run overlay creation, sync, ...""" - def optionally ( call, option, *args, **kw ): - if OPTION ( option ): - return call ( *args, **kw ) - # --- end of optionally (...) --- - - 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() - - ## this runs _nosync() or _sync(), depending on extra_opts->nosync - repo_list.sync() - - set_action_done ( "sync" ) - - 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() --- - - def run_overlay_create(): - if "create" in actions_done: return - #run_sync() - try: - global overlay_creator - overlay_creator = OverlayCreator ( - skip_manifest = OPTION ( 'skip_manifest' ), - incremental = OPTION ( 'incremental' ), - allow_write = OPTION ( 'write_overlay' ), - immediate_ebuild_writes = OPTION ( 'immediate_ebuild_writes' ), - ) - - repo_list.add_packages ( overlay_creator.add_package ) - - overlay_creator.run ( close_when_done=True ) - - optionally ( overlay_creator.write_overlay, 'write_overlay' ) - optionally ( overlay_creator.show_overlay, 'show_overlay' ) - if OPTION ( 'print_stats' ): - print ( "\n" + overlay_creator.stats_str() ) - - set_action_done ( "create" ) - - except KeyboardInterrupt: - die ( "Interrupted", DIE.INTERRUPT ) - except: - if HIDE_EXCEPTIONS: - die ( "Overlay creation failed.", DIE.OV_CREATE ) - else: - raise - finally: - if 'overlay_creator' in locals() and not overlay_creator.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_creator.close() - # --- end of run_overlay_create() --- - - # get args - # imports roverlay.argutil (deleted when done) - try: - import roverlay.argutil - except ImportError: - if HIDE_EXCEPTIONS: - die ( "Cannot import roverlay modules!", DIE.IMPORT ) - else: - raise - - COMMAND_DESCRIPTION = { - 'sync' : 'sync repos', - 'create' : 'create the overlay ' - '(implies sync, override with --nosync)', - 'depres_console' : \ - 'run an interactive depres console (highly experimental)', - 'depres' : 'this is an alias to \'depres_console\'', - 'nop' : 'does nothing', - } - - - DEFAULT_CONFIG_FILE = None - # search for the config file if roverlay has been installed - if ROVERLAY_INSTALLED: - cfg = None - config_dir = None - - for config_dir in CONFIG_DIRS: - cfg = config_dir + os.sep + CONFIG_FILE_NAME - if os.path.isfile ( cfg ): - DEFAULT_CONFIG_FILE = cfg - break - - del config_dir, cfg - elif os.path.exists ( CONFIG_FILE_NAME ): - DEFAULT_CONFIG_FILE = CONFIG_FILE_NAME - - - commands, config_file, additional_config, extra_opts = \ - roverlay.argutil.parse_argv ( - command_map=COMMAND_DESCRIPTION, - default_config_file=DEFAULT_CONFIG_FILE, - ) - - OPTION = extra_opts.get - - del roverlay.argutil - - # -- determine commands to run - # (TODO) could replace this section when adding more actions - # imports roverlay.remote, roverlay.overlay.creator - - actions = set ( filter ( lambda x : x != 'nop', commands ) ) - - 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!", DIE.NOP ) - - # -- load config - - # imports: roverlay, roverlay.config.entryutil (if --help-config) - - try: - import roverlay - except ImportError: - if HIDE_EXCEPTIONS: - die ( "Cannot import roverlay modules!", DIE.IMPORT ) - else: - raise - - try: - roverlay.setup_initial_logger() - - conf = roverlay.load_config_file ( - config_file, - extraconf=additional_config - ) - del config_file, additional_config - except: - if not config_file: - sys.stderr.write ( '!!! No config file found.\n' ) - - if HIDE_EXCEPTIONS: - die ( - "Cannot load config file {!r}.".format ( config_file ), DIE.CONFIG - ) - else: - raise - - if OPTION ( 'list_config' ): - try: - from roverlay.config.entryutil import list_entries - print ( "== main config file ==\n" ) - print ( list_entries() ) - except: - raise - die ( "Cannot list config entries!" ) - - EXIT_AFTER_CONFIG = True - - if OPTION ( 'print_config' ): - try: - conf.visualize ( into=sys.stdout ) - except: - die ( "Cannot print config!" ) - EXIT_AFTER_CONFIG = True - - if OPTION ( 'print_package_rules' ): - # no try-/catch block here - - import roverlay.packagerules.rules - - HLINE = "".rjust ( 79, '-' ) - print ( HLINE ) - print ( - str ( roverlay.packagerules.rules.PackageRules.get_configured() ) - ) - print ( HLINE ) - - EXIT_AFTER_CONFIG = True - - # -- end of EXIT_AFTER_CONFIG entries - - if 'EXIT_AFTER_CONFIG' in locals() and EXIT_AFTER_CONFIG: - pass - #sys.exit ( os.EX_OK ) - - # switch to depres console - elif 'depres_console' in actions or 'depres' in actions: - if len ( actions ) != 1: - die ( "depres_console cannot be run with other commands!", DIE.USAGE ) - - try: - from roverlay.depres.simpledeprule.console import DepResConsole - con = DepResConsole() - con.run() - sys.exit ( os.EX_OK ) - except ImportError: - if HIDE_EXCEPTIONS: - die ( "Cannot import depres console!", DIE.IMPORT ) - else: - raise - except: - if HIDE_EXCEPTIONS: - die ( "Exiting on console error!", DIE.ERR ) - else: - raise - - else: - # sync/create - # -- import roverlay modules - - 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 methods (and some vars) - # imports: nothing - - #repo_list = None - #overlay_creator = None - - actions_done = set() - set_action_done = actions_done.add - - # -- run - - # 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!".format ( - actions ), DIE.CMD_LEFTOVER - ) -# --- end of main() --- +ROVERLAY_INSTALLED = False if __name__ == '__main__': - roverlay_main() -elif not 'pydoc' in sys.modules: - die ( "Please don't import this script...", DIE.BAD_USAGE ) + roverlay.main.main ( + ROVERLAY_INSTALLED = ROVERLAY_INSTALLED + ) diff --git a/roverlay.py b/roverlay/main.py old mode 100755 new mode 100644 similarity index 85% copy from roverlay.py copy to roverlay/main.py index d18a987..b525ffe --- a/roverlay.py +++ b/roverlay/main.py @@ -1,38 +1,35 @@ -#!/usr/bin/python -OO +# R overlay -- main() # -*- coding: utf-8 -*- -# R overlay -- main script # Copyright (C) 2012 André Erdmann # Distributed under the terms of the GNU General Public License; # either version 2 of the License, or (at your option) any later version. """main script for R overlay creation""" -__all__ = [ 'DIE', 'roverlay_main' ] +__all__ = [ 'main' ] import os import sys +import time # roverlay modules will be imported later -ROVERLAY_INSTALLED = False -HIDE_EXCEPTIONS = False -CONFIG_FILE_NAME = "R-overlay.conf" - -if ROVERLAY_INSTALLED: - # directories where the config file could be found, in order: - # * ${PWD} - # * user roverlay dir (${HOME}/roverlay) - # * system config dir /etc/roverlay - CONFIG_DIRS = tuple (( - '.', - ( - ( os.getenv ( 'HOME' ) or os.path.expanduser ( '~' ) ) - + os.sep + 'roverlay' - ), - # os.sep is '/' if /etc exists, so don't care about that - '/etc/roverlay', - )) +DEFAULT_CONFIG_FILE_NAME = "R-overlay.conf" +# directories where the config file could be found if roverlay has been +# installed, in order: +# * ${PWD} +# * user roverlay dir (${HOME}/roverlay) +# * system config dir /etc/roverlay +CONFIG_DIRS = tuple (( + '.', + ( + ( os.getenv ( 'HOME' ) or os.path.expanduser ( '~' ) ) + + os.sep + 'roverlay' + ), + # os.sep is '/' if /etc exists, so don't care about that + '/etc/roverlay', +)) class DIE ( object ): @@ -66,8 +63,19 @@ class DIE ( object ): # --- DIE: exit codes --- die = DIE.die -def roverlay_main(): - """roverlay.py main() - parse args, run overlay creation, sync, ...""" +def main ( + ROVERLAY_INSTALLED, + HIDE_EXCEPTIONS=False, + CONFIG_FILE_NAME=DEFAULT_CONFIG_FILE_NAME +): + """main() - parse args, run overlay creation, sync, ... + + arguments: + * ROVERLAY_INSTALLED -- whether roverlay has been installed or not + * HIDE_EXCEPTIONS -- hide exceptions? (optional, defaults to False) + * CONFIG_FILE_NAME -- name of the config file (optional, defaults to + "R-overlay.conf") + """ def optionally ( call, option, *args, **kw ): if OPTION ( option ): return call ( *args, **kw ) @@ -83,7 +91,7 @@ def roverlay_main(): force_distroot = OPTION ( 'force_distroot' ) ) - ## extra_opts->distdir ... TODO + ## extra_opts->distdir if 'distdirs' in extra_opts: repo_list.add_distdirs ( OPTION ( 'distdirs' ) ) else: @@ -91,7 +99,10 @@ def roverlay_main(): repo_list.load() ## this runs _nosync() or _sync(), depending on extra_opts->nosync + t_start = time.time() repo_list.sync() + global sync_time + sync_time = time.time() - t_start set_action_done ( "sync" ) @@ -120,7 +131,14 @@ def roverlay_main(): immediate_ebuild_writes = OPTION ( 'immediate_ebuild_writes' ), ) + if 'sync_time' in globals(): + overlay_creator.set_timestats ( 'sync_packages', sync_time ) + + t_start = time.time() repo_list.add_packages ( overlay_creator.add_package ) + overlay_creator.set_timestats ( + 'add_packages', time.time() - t_start + ) overlay_creator.run ( close_when_done=True ) @@ -335,9 +353,4 @@ def roverlay_main(): "Some actions (out of {!r}) could not be performed!".format ( actions ), DIE.CMD_LEFTOVER ) -# --- end of main() --- - -if __name__ == '__main__': - roverlay_main() -elif not 'pydoc' in sys.modules: - die ( "Please don't import this script...", DIE.BAD_USAGE ) +# --- end of main (...) ---