def preload_for_main(): """Return arguments dict, sinner bol, and logging object.""" args = _arguments() # set boolean objects for spinner and stream logging. if args['debug'] is True: run_spinner = False stream_logs = True elif args['quiet'] is True: run_spinner = False stream_logs = False else: run_spinner = True stream_logs = False if 'git_repo_path' not in args or not args['git_repo_path']: args['git_repo_path'] = os.path.join(tempfile.gettempdir(), 'yaprt_temp_git_dir') try: os.makedirs(args['git_repo_path']) except OSError: pass # Load the logging. _logging = logger.LogSetup(debug_logging=args['debug']) log = _logging.default_logger(name='repo_builder', enable_stream=stream_logs) return args, run_spinner, log
def main(): """Run the main app. This application will create all Python wheel files from within an environment. The purpose is to create pre-compiled python wheels from the RPC playbooks. """ # Parse input arguments user_args = _user_args() # Load the logging _logging = logger.LogSetup(debug_logging=user_args['debug']) if user_args['quiet'] is True or user_args['debug'] is False: stream = False else: stream = True _logging.default_logger(name='rpc_wheel_builder', enable_stream=stream) global LOG LOG = logger.getLogger(name='rpc_wheel_builder') # Create the output path output_path = _get_abs_path(path=user_args['output']) LOG.info('Getting output path') _mkdirs(path=output_path) # Create the build path LOG.info('Getting build path') if user_args['build_dir'] is not None: build_path = _get_abs_path(path=user_args['build_dir']) _mkdirs(path=build_path) else: build_path = tempfile.mkdtemp(prefix='rpc_wheels_build_') pre_input = user_args['pre_input'] if pre_input: pre_input_path = _get_abs_path(path=user_args['pre_input']) with open(pre_input_path, 'rb') as f: global PYTHON_PACKAGES PYTHON_PACKAGES = json.loads(f.read()) else: # Get the input path LOG.info('Getting input path') input_path = _get_abs_path(path=user_args['input']) new_setup(user_args=user_args, input_path=input_path, output_path=output_path, quiet=stream) # Create all of the python package wheels make_wheels(wheel_dir=output_path, build_dir=build_path, quiet=stream) # if git_repos was defined save all of the sources to the defined location git_repos_path = user_args.get('git_repos') if git_repos_path: _store_git_repos(git_repos_path, quiet=stream)
def setUp(self): self.log = logger.LogSetup() self.uid_patched = mock.patch('cloudlib.logger.os.getuid') self.uid = self.uid_patched.start() self.env_patched = mock.patch('cloudlib.logger.os.path.expanduser') self.env = self.env_patched.start() self.idr_patched = mock.patch('cloudlib.logger.os.path.isdir') self.idr = self.idr_patched.start() self.stat_patched = mock.patch('cloudlib.logger.os.stat') self.stat = self.stat_patched.start()
def setUp(self): self.rh_patched = mock.patch( 'cloudlib.logger.handlers.RotatingFileHandler') self.rh = self.rh_patched.start() self.sh_patched = mock.patch('cloudlib.logger.logging.StreamHandler') self.sh = self.sh_patched.start() self.ch_patched = mock.patch( 'cloudlib.logger.logging.Logger.callHandlers') self.ch_patched.start() self.log = logger.LogSetup() self._log = mock.Mock() self._handler = mock.Mock()
def execute(): """This is the run section of the application Turbolift.""" if len(sys.argv) <= 1: raise SystemExit( 'No Arguments provided. use [--help] for more information.') # Capture user arguments _args = arguments.ArgumentParserator( arguments_dict=turbolift.ARGUMENTS, env_name='TURBO', epilog=turbolift.VINFO, title='Turbolift', detail='Multiprocessing Swift CLI tool.', description='Manage Swift easily and fast.') user_args = _args.arg_parser() user_args['run_indicator'] = True debug_log = False stream_logs = True # Load system logging if user_args.get('debug'): debug_log = True user_args['run_indicator'] = False # Load system logging if user_args.get('quiet'): stream_logs = False user_args['run_indicator'] = False _logging = logger.LogSetup(debug_logging=debug_log, colorized_messages=user_args.get( 'colorized', False)) _logging.default_logger(name='turbolift', enable_stream=stream_logs) job = worker.Worker(job_args=user_args) job.run_manager()
def test_logger_debug_logging_enabled(self): log = logger.LogSetup(debug_logging=True) self.assertEqual(log.debug_logging, True)
def test_logger_override_max_size(self): log = logger.LogSetup(max_size=10) self.assertEqual(log.max_size, 10485760)
def test_logger_override_max_backup(self): log = logger.LogSetup(max_backup=10) self.assertEqual(log.max_backup, 10)
def main(): """Run the main app. This application will create all Python wheel files from within an environment. The purpose is to create pre-compiled python wheels from the RPC playbooks. """ # Parse input arguments user_args = _user_args() # Load the logging _logging = logger.LogSetup(debug_logging=user_args['debug']) if user_args['quiet'] is True or user_args['debug'] is False: stream = False else: stream = True _logging.default_logger(name='rpc_wheel_builder', enable_stream=stream) global LOG LOG = logger.getLogger(name='rpc_wheel_builder') # Create the output path output_path = _get_abs_path(path=user_args['output']) LOG.info('Getting output path') _mkdirs(path=output_path) # Create the build path LOG.info('Getting build path') indicator_kwargs = { 'debug': user_args['debug'], 'quiet': user_args['quiet'], 'note': 'Gather dependencies... ' } with IndicatorThread(**indicator_kwargs): if user_args['build_dir'] is not None: build_path = _get_abs_path(path=user_args['build_dir']) _mkdirs(path=build_path) else: build_path = tempfile.mkdtemp(prefix='rpc_wheels_build_') pre_input = user_args['pre_input'] if pre_input: pre_input_path = _get_abs_path(path=user_args['pre_input']) with open(pre_input_path, 'rb') as f: global PYTHON_PACKAGES PYTHON_PACKAGES = json.loads(f.read()) else: # Get the input path LOG.info('Getting input path') new_setup(user_args=user_args, input_path=_get_abs_path(path=user_args['input'])) indicator_kwargs['note'] = 'Building wheels... ' with IndicatorThread(**indicator_kwargs): # Create all of the python package wheels make_wheels(wheel_dir=output_path, build_dir=build_path) indicator_kwargs['note'] = 'Generating build log... ' with IndicatorThread(**indicator_kwargs): # Get a timestamp and create a report file utctime = datetime.datetime.utcnow() utctime = utctime.strftime("%Y%m%d_%H%M%S") backup_name = '%s-build-report-%s.json' % (user_args['release'], utctime) output_report_file = os.path.join(output_path, 'json-reports', backup_name) # Make the directory if needed _mkdirs(path=os.path.dirname(output_report_file)) # Generate a timestamped report file LOG.info('Generating packaging report [ %s ]', output_report_file) with open(output_report_file, 'wb') as f: f.write(json.dumps(PYTHON_PACKAGES, indent=2, sort_keys=True)) # If link_dir is defined create a link to all built wheels. links_path = user_args.get('link_dir') if links_path: indicator_kwargs['note'] = 'Creating file links... ' with IndicatorThread(**indicator_kwargs): links_path = _get_abs_path(path=links_path) LOG.info('Creating Links at [ %s ]', links_path) _mkdirs(path=links_path) # Change working directory. os.chdir(links_path) # Create all the links for inode in PYTHON_PACKAGES['built_files']: try: dest_link = os.path.join(links_path, inode) # Remove the destination inode if it exists if os.path.exists(dest_link): os.remove(dest_link) # Create the link using the relative path os.symlink( os.path.relpath(os.path.join(output_path, inode)), dest_link) except OSError as exp: LOG.warn('Error Creating Link: [ %s ] Error: [ %s ]', inode, exp) else: LOG.debug('Link Created: [ %s ]', dest_link) # if git_repos was defined save all of the sources to the defined location git_repos_path = user_args.get('git_repos') if git_repos_path: indicator_kwargs['note'] = 'Storing updated git sources...' with IndicatorThread(**indicator_kwargs): LOG.info('Updating git sources [ %s ]', links_path) _store_git_repos(_get_abs_path(path=git_repos_path))