def _handle_pack_command(self): """Pack the current mamba application """ try: mamba_services = commons.import_services() mamba_services.config.Application('config/application.json') except Exception: mamba_services_not_found() use_egg = self.options.subOptions.opts['egg'] command = 'bdist_egg' if use_egg else 'sdist' try: print('Packing {} application into {} format...'.format( self.options.subOptions.opts['name'], 'egg' if use_egg else 'source' ).ljust(73), end='') Packer().pack_application( command, self.options.subOptions, mamba_services.config.Application() ) print('[{}]'.format(darkgreen('Ok'))) except: print('[{}]'.format(darkred('Fail'))) raise sys.exit(-1)
def _handle_uninstall_command(self): """Uninstall a package using pip (we don't want to reinvent the wheel) """ if not PIP_IS_AVAILABLE: raise usage.UsageError('pip is not available') try: mamba_services = commons.import_services() mamba_services.config.Application('config/application.json') except Exception: mamba_services_not_found() name = 'mamba-{}'.format(mamba_services.config.Application( 'config/application.json').name.lower() ) print('Uninstalling {}...'.format(name).ljust(73), end='') try: p = subprocess.Popen( ['pip', 'uninstall', name], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE ) stdout, error = p.communicate('y') if error is not '': raise RuntimeError(error) elif p.returncode is not 0: raise RuntimeError(stdout) else: print('[{}]'.format(darkgreen('Ok'))) except: print('[{}]'.format(darkred('Fail'))) raise
def _handle_configure_command(self): """Take care of SQL configuration to generate config/database.json file """ try: mamba_services = commons.import_services() except Exception: mamba_services_not_found() if not self.options.subOptions.opts['noquestions']: query = ( 'You are going to generate (and possible overwrite) a ' 'database.json configuration file for your database. Are you ' 'sure do you want to do that? (Ctrl+c to abort)' ) if commons.Interaction.userquery(query) == 'No': print('Skiping...') sys.exit(0) options = { 'uri': self.options.subOptions.opts['uri'], 'min_threads': self.options.subOptions.opts['min-threads'], 'max_threads': self.options.subOptions.opts['max-threads'], 'auto_adjust_pool_size': (True if ( self.options.subOptions.opts['autoadjust-pool']) else False ), 'create_table_behaviours': { 'create_table_if_not_exists': (True if ( self.options.subOptions.opts['create-if-not-exists']) else False ), 'drop_table': (True if ( self.options.subOptions['drop-table']) else False ) }, 'drop_table_behaviours': { 'drop_if_exists': (True if( self.options.subOptions.opts['drop-if-exists']) else False ), 'restrict': (False if( self.options.subOptions.opts['non-restrict']) else True ), 'cascade': (True if( self.options.subOptions.opts['cascade']) else False ) } } try: print('Writing databse config file...'.ljust(73), end='') mamba_services.config.Database.write(options) print('[{}]'.format(darkgreen('Ok'))) except OSError: print('[{}]'.format(darkred('Fail'))) raise sys.exit(-1)
def parseArgs(self, name=None): """Parse command arguments """ try: mamba_services = commons.import_services() except Exception: mamba_services_not_found() # if a name is not provided we use the application name instead if name is None: self['name'] = mamba_services.config.Application().name
def _prepare_model_db(self): try: mamba_services = commons.import_services() except Exception: mamba_services_not_found() # load database configuration mamba_services.config.Database('config/database.json') # this is needed to don't have a threadpool waiting forever db = database.Database(DummyThreadPool()) Model.database = db return mamba_services, db
def _handle_install_command(self): """Install the current mamba application or a packed one """ if self.options.subOptions.opts['filepath'] is None: try: mamba_services = commons.import_services() except Exception: mamba_services_not_found() self._handle_install_current_directory(mamba_services) else: self._handle_install_already_packed_application( self.options.subOptions.opts['filepath'])
def _handle_install_command(self): """Install the current mamba application or a packed one """ if self.options.subOptions.opts['filepath'] is None: try: mamba_services = commons.import_services() except Exception: mamba_services_not_found() self._handle_install_current_directory(mamba_services) else: self._handle_install_already_packed_application( self.options.subOptions.opts['filepath'] )
def parseArgs(self, name=None): """Parse command arguments """ try: mamba_services = commons.import_services() except Exception: mamba_services_not_found() # if a name is not provided we use the application name instead if name is None: self['name'] = 'mamba-{}'.format( mamba_services.config.Application( 'config/application.json').name.lower() ) else: self['name'] = name
def _handle_install_command(self): """Install the current mamba application or a packed one """ if PIP_IS_AVAILABLE and self._is_pip_installable(): self._pip_install_package() return None if self.options.subOptions.opts['filepath'] is None: try: mamba_services = commons.import_services() except Exception: mamba_services_not_found() self._handle_install_current_directory(mamba_services) else: self._handle_install_already_packed_application( self.options.subOptions.opts['filepath'] )
def process(self): """I process the Model commands """ try: mamba_services = commons.import_services() del mamba_services except Exception: mamba_services_not_found() if self.options.subOptions.opts['name'] is None: print(self.options.subOptions) sys.exit(-1) if self.options.subOptions.opts['dump']: self._dump_model() sys.exit(0) self._write_model() sys.exit(0)
def _handle_uninstall_command(self): """Uninstall a package using pip (we don't want to reinvent the wheel) """ if not PIP_IS_AVAILABLE: raise usage.UsageError('pip is not available') try: mamba_services = commons.import_services() mamba_services.config.Application('config/application.json') except Exception: mamba_services_not_found() name = 'mamba-{}'.format(mamba_services.config.Application( 'config/application.json').name.lower() ) print('Uninstalling {}...'.format(name).ljust(73), end='') try: p = subprocess.Popen( ['pip', 'uninstall', name], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE ) p.communicate('y') # PROD-3384: previous code was checking stderr for errors but inside our # vagrant virtual environments stderr was returning a message telling us # to upgrade pip. This was resulting in the user being incorrectly told # the uninstall command had failed. # Now checking return code from command: should be 0 if the command was # successfully executed if p.returncode == 0: print('[{}]'.format(darkgreen('Ok'))) else: raise Exception( 'Unexpected output from pip install command: {}'.format(p.returncode) ) except: print('[{}]'.format(darkred('Fail'))) raise
def _pip_install_package(self): """Use pip to install a package. Requires package to be in a state which is pip installable, i.e. that a setup.py is already specified. Note that the legacy code is dynamically generating the setup.py file. See: Packer.write_setup_script """ try: mamba_services = commons.import_services() mamba_services.config.Application('config/application.json') except Exception: mamba_services_not_found() name = 'mamba-{}'.format( mamba_services.config.Application('config/application.json').name.lower() ) print('Installing {}...'.format(name).ljust(73), end='') try: args = ['pip', 'install', '--upgrade'] if self.options.subOptions['user']: args.append(['--user']) args.append(os.curdir) p = subprocess.call(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if p == 0: print('[{}]'.format(darkgreen('Ok'))) else: raise Exception('Unexpected output from pip install command: {}'.format(p)) except: print('[{}]'.format(darkred('Fail'))) raise
def parseArgs(self, path=None): """Parse command arguments """ if path is None: try: mamba_services = commons.import_services() assert mamba_services self['filepath'] = None # if a name is not provided we use the application name instead self['name'] = 'mamba-{}'.format( mamba_services.config.Application( 'config/application.json').name.lower()) except Exception: mamba_services_not_found() else: fp = filepath.FilePath(path) if fp.exists(): self['filepath'] = fp else: print('{} does not exists... using it as name'.format(path)) # if a name is not provided we use the application name instead self['name'] = path
def parseArgs(self, path=None): """Parse command arguments """ if path is None: try: mamba_services = commons.import_services() assert mamba_services self['filepath'] = None # if a name is not provided we use the application name instead self['name'] = 'mamba-{}'.format( mamba_services.config.Application( 'config/application.json').name.lower() ) except Exception: mamba_services_not_found() else: fp = filepath.FilePath(path) if fp.exists(): self['filepath'] = fp else: print('{} does not exists... using it as name'.format(path)) # if a name is not provided we use the application name instead self['name'] = path