def pre_run(self): # Hack around http://bugs.python.org/issue9253 ? if "--version" in sys.argv: import pkg_resources version = pkg_resources.get_distribution("elasticluster").version print("elasticluster version %s" % version) sys.exit(0) cli.app.CommandLineApp.pre_run(self) # print *all* Python warnings through the logging subsystem warnings.resetwarnings() warnings.simplefilter('once') utils.redirect_warnings(logger='gc3.elasticluster') # Set verbosity level loglevel = max(1, logging.WARNING - 10 * max(0, self.params.verbose)) coloredlogs.install(logger=log, level=loglevel) # In debug mode, avoid forking if self.params.verbose > 3: log.DO_NOT_FORK = True log.raiseExceptions = True if not os.path.isdir(self.params.storage): # We do not create *all* the parents, but we do create the # directory if we can. try: os.makedirs(self.params.storage) except OSError as ex: sys.stderr.write("Unable to create storage directory: " "%s\n" % (str(ex))) sys.exit(1) # If no configuration file was specified and default does not exists... if not os.path.isfile(self.params.config): if self.params.config == self.default_configuration_file: # Copy the default configuration file to the user's home if not os.path.exists(os.path.dirname(self.params.config)): os.mkdir(os.path.dirname(self.params.config)) template = resource_filename( 'elasticluster', 'share/etc/config.template') log.warning("Deploying default configuration file to %s.", self.params.config) shutil.copyfile(template, self.params.config) else: # Exit if supplied configuration file does not exists. if not os.path.isfile(self.params.config): sys.stderr.write( "Unable to read configuration file `%s`.\n" % self.params.config) sys.exit(1) assert self.params.func, ("No subcommand defined in `ElastiCluster.setup()") try: self.params.func.pre_run() except (RuntimeError, ConfigurationError) as ex: sys.stderr.write(str(ex).strip()) sys.stderr.write('\n') sys.exit(1)
def pre_run(self): # Hack around http://bugs.python.org/issue9253 ? if "--version" in sys.argv: import pkg_resources version = pkg_resources.get_distribution("elasticluster").version print("elasticluster version %s" % version) sys.exit(0) cli.app.CommandLineApp.pre_run(self) # print *all* Python warnings through the logging subsystem warnings.resetwarnings() warnings.simplefilter('once') utils.redirect_warnings(logger='gc3.elasticluster') # Set verbosity level loglevel = max(logging.DEBUG, logging.WARNING - 10 * max(0, self.params.verbose)) coloredlogs.install(logger=log, level=loglevel) log.setLevel(loglevel) # In debug mode, avoid forking if self.params.verbose > 3: log.DO_NOT_FORK = True log.raiseExceptions = True if not os.path.isdir(self.params.storage): # We do not create *all* the parents, but we do create the # directory if we can. try: os.makedirs(self.params.storage) except OSError as ex: sys.stderr.write("Unable to create storage directory: " "%s\n" % (str(ex))) sys.exit(1) self.check_config_or_copy_template() assert self.params.func, "No subcommand defined in `ElastiCluster.setup()" try: self.params.func.pre_run() except (RuntimeError, ConfigurationError) as ex: sys.stderr.write(str(ex).strip()) sys.stderr.write('\n') sys.exit(1)
def pre_run(self): # Hack around http://bugs.python.org/issue9253 ? if "--version" in sys.argv: import pkg_resources version = pkg_resources.get_distribution("elasticluster").version print("elasticluster version %s" % version) sys.exit(0) cli.app.CommandLineApp.pre_run(self) # print *all* Python warnings through the logging subsystem warnings.resetwarnings() warnings.simplefilter('once') utils.redirect_warnings(logger='gc3.elasticluster') # Set verbosity level loglevel = max(logging.DEBUG, logging.WARNING - 10 * max(0, self.params.verbose)) coloredlogs.install(logger=log, level=loglevel) log.setLevel(loglevel) # In debug mode, avoid forking if self.params.verbose > 3: log.DO_NOT_FORK = True log.raiseExceptions = True if not os.path.isdir(self.params.storage): # We do not create *all* the parents, but we do create the # directory if we can. try: os.makedirs(self.params.storage) except OSError as ex: sys.stderr.write("Unable to create storage directory: " "%s\n" % (str(ex))) sys.exit(1) self.check_config_or_copy_template() assert self.params.func, "No subcommand defined in `ElastiCluster.setup()" try: self.params.func.pre_run() except (RuntimeError, ConfigurationError) as ex: sys.stderr.write(str(ex).strip()) sys.stderr.write('\n') sys.exit(1)
def pre_run(self): # Hack around http://bugs.python.org/issue9253 ? if "--version" in sys.argv: import pkg_resources version = pkg_resources.get_distribution("elasticluster").version print("elasticluster version %s" % version) sys.exit(0) cli.app.CommandLineApp.pre_run(self) # print *all* Python warnings through the logging subsystem warnings.resetwarnings() warnings.simplefilter('once') utils.redirect_warnings(logger='gc3.elasticluster') # Set verbosity level loglevel = max(logging.DEBUG, logging.WARNING - 10 * max(0, self.params.verbose)) coloredlogs.install(logger=log, level=loglevel) log.setLevel(loglevel) # In debug mode, avoid forking if self.params.verbose > 3: log.DO_NOT_FORK = True log.raiseExceptions = True if not os.path.isdir(self.params.storage): # We do not create *all* the parents, but we do create the # directory if we can. try: os.makedirs(self.params.storage) except OSError as ex: sys.stderr.write("Unable to create storage directory: " "%s\n" % (str(ex))) sys.exit(1) # If no configuration file was specified and default does not exists and the user did not create a config dir... if not os.path.isfile( self.params.config) and not os.path.isdir(self.params.config + '.d'): if self.params.config == self.default_configuration_file: # Copy the default configuration file to the user's home if not os.path.exists(os.path.dirname(self.params.config)): os.mkdir(os.path.dirname(self.params.config)) template = resource_filename('elasticluster', 'share/etc/config.template') log.warning("Deploying default configuration file to %s.", self.params.config) shutil.copyfile(template, self.params.config) else: # Exit if supplied configuration file does not exists. if not os.path.isfile(self.params.config): sys.stderr.write( "Unable to read configuration file `%s`.\n" % self.params.config) sys.exit(1) assert self.params.func, ( "No subcommand defined in `ElastiCluster.setup()") try: self.params.func.pre_run() except (RuntimeError, ConfigurationError) as ex: sys.stderr.write(str(ex).strip()) sys.stderr.write('\n') sys.exit(1)