def _configure_packages(self, project, parser): packages = parser.parse_packages() for package in packages: package.company = project.replace_constants(package.company) package.name = project.replace_constants(package.name) package.config = project.replace_constants(package.config) package.version = project.replace_constants(package.version) if len(package.deliveries) > 0: for i in range(len(package.deliveries)): package.deliveries[i] = project.replace_constants( package.deliveries[i]) items = [] items.extend(package.items) package.items = [] if package.format_name() in project.packages.keys(): raise PyvenException('Package already added --> ' + package.format_name()) elif package.to_retrieve and package.repo not in project.repositories.keys( ) and package.repo not in [Step.LOCAL_REPO.name, 'workspace']: raise PyvenException('Package repository not declared --> ' + package.format_name() + ' : repo ' + package.repo) else: for item in items: item = project.replace_constants(item) if item not in project.artifacts.keys(): raise PyvenException('Package ' + package.format_name() + ' : Artifact not declared --> ' + item) else: package.items.append(project.artifacts[item]) Logger.get().info('Package ' + package.format_name() + ' : Artifact added --> ' + item) project.packages[package.format_name()] = package Logger.get().info('Package added --> ' + package.format_name()) if not package.publish: Logger.get().info('Package ' + package.format_name() + ' --> publishment disabled') for package in packages: for extension in package.extensions: extension = project.replace_constants(extension) if extension not in project.packages.keys(): raise PyvenException( 'Package ' + package.format_name() + ' : Package extension not declared --> ' + extension) elif project.packages[extension].to_retrieve: raise PyvenException( 'Package ' + package.format_name() + ' : Cannot extend a package to be retrieved --> ' + extension) else: package.items.extend(project.packages[extension].items) Logger.get().info('Package ' + package.format_name() + ' : Package extension added --> ' + extension)
def parse_xml(self, file): tree = None if not os.path.isfile(file): raise PyvenException('Package file not available : ' + self.format_name('_') + '.xml') try: tree = etree.parse(file) except Exception as e: pyven_exception = PyvenException('') pyven_exception.args = e.args raise pyven_exception return tree
def _configure_projects(self, project, parser): directories = parser.parse_projects() for directory in directories: if not os.path.isdir(os.path.join(project.path, directory)): raise PyvenException('Subproject directory does not exist : ' + directory) else: full_path = os.path.join(project.path, directory) subproject = Project(full_path, parser.plugins_manager.plugins.copy()) subproject.constants = project.constants.copy() if not self._process(subproject): raise PyvenException('Subproject ' + full_path + ' --> configuration failed') Logger.get().info('Added subproject --> ' + directory)
def _format_call(self, clean=False): exe = 'msbuild.exe' if self.dot_net_version is not None: Logger.get().info('Using .NET ' + self.dot_net_version) exe = os.path.join(os.environ.get('WINDIR'), 'Microsoft.NET', 'Framework', self.dot_net_version, exe) elif self.project.endswith('.dproj'): Logger.get().info('Using .NET v3.5') exe = os.path.join(os.environ.get('WINDIR'), 'Microsoft.NET', 'Framework', 'v3.5', exe) call = [exe, self.project] call.append( '/consoleLoggerParameters:NoSummary;ErrorsOnly;WarningsOnly') if self.project.endswith('.sln'): call.append('/property:Configuration=' + self.configuration) call.append('/property:Platform=' + self.architecture) if clean: call.append('/t:clean') elif self.project.endswith('.dproj'): call.append('/p:config=' + self.configuration) call.append('/p:platform=' + self.architecture) if clean: call.append('/t:clean') else: call.append('/t:build') else: raise PyvenException( 'Project format not supported : ' + self.project, 'Supported formats : *.sln, *.dproj') for option in self.options: call.append(option) Logger.get().info(' '.join(call)) return call
def process(self, verbose=False, warning_as_error=False): if not os.path.isfile(os.path.join(self.cwd, self.filename)): raise PyvenException('Test file not found : ' + os.path.join(self.path, self.filename)) if os.path.isdir(self.cwd): Logger.get().info('Running test : ' + self.filename) if os.path.isfile( os.path.join(self.cwd, self._format_report_name())): os.remove(os.path.join(self.cwd, self._format_report_name())) self.duration, out, err, returncode = self._call_command( self._format_call()) self.parser.parse( os.path.join(self.cwd, self._format_report_name())) if returncode != 0: self.status = pyven.constants.STATUS[1] if os.path.isfile( os.path.join(self.cwd, self._format_report_name())): self.errors = self.parser.errors else: msg = 'Could not find TRX report --> ' + os.path.join( self.path, self._format_report_name()) self.errors.append([msg]) Logger.get().error(msg) Logger.get().error('Test failed : ' + self.filename) else: self.status = pyven.constants.STATUS[0] Logger.get().info('Test OK : ' + self.filename) return returncode == 0 Logger.get().error('Unknown directory : ' + self.path) return False
def load(self): for name, version in self.plugins.items(): plugin_file = os.path.join( PluginsManager.DIR, PluginsManager.plugin_filename(name, version)) if not os.path.isfile(plugin_file): raise PyvenException('Unable to find plugin : ' + plugin_file) sys.path.append(plugin_file) self.modules[name] = __import__(name + '_plugin.parser', globals(), locals(), ['get'], 0)
def pack(self, repo): Logger.get().info('Package ' + self.format_name() + ' --> Creating archive ' + self.basename()) if not os.path.isdir(self.location(repo.url)): os.makedirs(self.location(repo.url)) if os.path.isfile(os.path.join(self.location(repo.url), self.basename())): os.remove(os.path.join(self.location(repo.url), self.basename())) ok = True errors = [] for item in self.items: if not os.path.isfile(os.path.join(item.location(repo.url), item.basename())): errors.append('Package item not found --> ' + os.path.join(item.location(repo.url), item.basename())) ok = False for d in self.directories: if not os.path.isdir(os.path.join(self.cwd, d)): errors.append('Directory not found --> ' + os.path.join(self.cwd, d)) ok = False if ok: zf = zipfile.ZipFile(os.path.join(self.location(repo.url), self.basename()), mode='w') try: for d in self.directories: Logger.get().info('Package ' + self.format_name() + ' --> Adding directory ' + d) root = os.path.basename(os.path.normpath(os.path.join(self.cwd, d))) for current_dir, dirs, files in os.walk(os.path.join(self.cwd, d)): for f in [os.path.join(current_dir, f) for f in files]: zf.write(os.path.join(self.cwd, f), f[f.find(root):]) Logger.get().info('Package ' + self.format_name() + ' --> Added file : ' + f) Logger.get().info('Package ' + self.format_name() + ' --> Added directory ' + d) for pattern in self.patterns: for file in glob.glob(os.path.join(self.cwd, pattern)): zf.write(file, os.path.basename(file)) Logger.get().info('Package ' + self.format_name() + ' --> Added file from pattern : ' + os.path.basename(file)) finally: zf.close() Logger.get().info('Package ' + self.format_name() + ' --> Created archive ' + self.basename()) utils.str_to_file(self.to_xml(), os.path.join(self.location(repo.url), self.format_name('_') + '.xml')) else: e = PyvenException('') e.args = tuple(errors) raise e return ok
def parse(self, file): result = [] if os.path.isfile(file): tree = etree.parse(file) doc_element = tree.getroot() if self.format == 'cppunit': result = self._parse_xml_cppunit(doc_element) else: raise PyvenException('Invalid XML format : ' + self.format) else: msg = ['XML report not found'] self.errors.append(msg) return result
def _configure_repositories(self, project, parser): repositories = parser.parse_repositories() project.repositories[Step.WORKSPACE.name] = Step.WORKSPACE project.repositories[Step.LOCAL_REPO.name] = Step.LOCAL_REPO for repo in repositories: if repo.name == 'workspace' or repo.name == Step.LOCAL_REPO.name: raise PyvenException('Repository name reserved --> ' + repo.name + ' : ' + repo.url) else: if repo.name in project.repositories.keys(): raise PyvenException('Repository already added --> ' + repo.name + ' : ' + repo.url) else: project.repositories[repo.name] = repo if repo.is_reachable(): if repo.release: Logger.get().info('Release repository added --> ' + repo.name + ' : ' + repo.url) else: Logger.get().info('Repository added --> ' + repo.name + ' : ' + repo.url) else: Logger.get().warning('Repository not accessible --> ' + repo.name + ' : ' + repo.url)
def _configure_artifacts(self, project, parser): artifacts = parser.parse_artifacts() for artifact in artifacts: artifact.company = project.replace_constants(artifact.company) artifact.name = project.replace_constants(artifact.name) artifact.config = project.replace_constants(artifact.config) artifact.version = project.replace_constants(artifact.version) if not artifact.to_retrieve: artifact.file = project.replace_constants(artifact.file) if artifact.format_name() in project.artifacts.keys(): raise PyvenException('Artifact already added --> ' + artifact.format_name()) elif artifact.to_retrieve and artifact.repo not in project.repositories.keys( ) and artifact.repo not in [Step.LOCAL_REPO.name, 'workspace']: raise PyvenException('Artifact repository not declared --> ' + artifact.format_name() + ' : repo ' + artifact.repo) else: project.artifacts[artifact.format_name()] = artifact Logger.get().info('Artifact added --> ' + artifact.format_name()) if not artifact.publish: Logger.get().info('Artifact ' + artifact.format_name() + ' --> publishment disabled')
def unpack(self, dir, repo, flatten=False): if not os.path.isfile(os.path.join(self.location(repo.url), self.basename())): raise PyvenException('Package not found at ' + self.location(repo.url) + ' : ' + self.format_name()) if not os.path.isdir(dir): os.makedirs(dir) if flatten: with zipfile.ZipFile(os.path.join(self.location(repo.url), self.basename()), "r") as z: z.extractall(dir) for item in self.items_from_xml(repo): shutil.copy2(item.file, os.path.join(dir, os.path.basename(item.file))) else: with zipfile.ZipFile(os.path.join(self.location(repo.url), self.basename()), "r") as z: z.extractall(os.path.join(dir, self.format_name('_'))) for item in self.items_from_xml(repo): full_dir = os.path.join(dir, self.format_name('_')) if not os.path.isdir(full_dir): os.makedirs(full_dir) shutil.copy2(item.file, os.path.join(full_dir, os.path.basename(item.file)))
def _intern(self, project): ok = True Logger.set_format(project) try: try: if project.path != os.getcwd(): if not os.path.isdir(project.path): raise PyvenException( 'Subproject path does not exist : ' + project.path) tic = time.time() ok = function(self, project) toc = time.time() Logger.get().info('Step time : ' + str(round(toc - tic, 3)) + ' seconds') except PyvenException as e: self.checker.errors.append(e.args) ok = False finally: Logger.set_format() return ok
class Item(object): if os.name == 'nt': PLATFORM = 'windows' elif os.name == 'posix': PLATFORM = 'linux' else: raise PyvenException('Unsupported platform') def __init__(self, company, name, config, version, repo, to_retrieve, publish): self.company = company self.name = name self.config = config self.version = version self.repo = repo self.to_retrieve = to_retrieve self.publish = publish def format_name(self, separator=':'): return self.company + separator + self.name + separator + self.config + separator + self.version def type(self): raise NotImplementedError def basename(self): raise NotImplementedError def item_specific_location(self): return os.path.join(Item.PLATFORM, self.company, self.name, self.config, self.version) def repo_location(self, repo): return os.path.join(repo, self.type() + 's') def location(self, repo): return os.path.join(self.repo_location(repo), self.item_specific_location())
def get_parser(self, name, cwd): if name not in self.modules.keys(): raise PyvenException('Plugin not available : ' + name) return self.modules[name].get(cwd)
import os from pyven.exceptions.exception import PyvenException MAJOR = 0 MINOR = 2 PATCH = 8 VERSION = '.'.join([str(MAJOR), str(MINOR), str(PATCH)]) PLATFORMS = ['linux', 'windows'] if os.name == 'nt': PLATFORM = PLATFORMS[1] elif os.name == 'posix': PLATFORM = PLATFORMS[0] else: raise PyvenException('Unsupported platform : ' + os.name, 'Supported platforms : windows, linux') STATUS = ['SUCCESS', 'FAILURE', 'UNKNOWN']
def main(args): tic = time.time() Logger.get().info('Pyven ' + cst.VERSION) parser = argparse.ArgumentParser() parser.add_argument('--version', action='version', version='1.0.0') parser.add_argument( '--display', '-d', action='store_true', help='display build report in the webbrowser right after build') parser.add_argument('--verbose', '-v', action='store_true', help='increase verbosity level') parser.add_argument('--warning-as-error', '-wae', dest='warning_as_error', action='store_true', help='consider warnings as errors') parser.add_argument( '--lines', '-l', dest='nb_lines', action='store', type=int, default=10, help='Number of errors/warnings to be displayed in the build report') parser.add_argument('--custom-pym', '-cp', dest='pym', action='store', type=str, default='pym.xml', help='pym file name') parser.add_argument('--release', '-r', action='store_true', help='enable deployment to release repositories') parser.add_argument('--overwrite', '-o', action='store_true', help='enable deployment to release repositories') parser.add_argument('--report-style', '-rs', dest='report_style', action='store', type=str, default='default', help='Sets the HTML report style') parser.add_argument('--multithread', '-m', dest='nb_threads', action='store', type=int, default=1, help='Number of threads for parallel build') parser.add_argument('step', choices=Pyven.STEPS + Pyven.UTILS, help='pyven step to be achieved') parser.add_argument( 'path', nargs='?', help='path to the delivery directory (used with "deliver" step only)') args = parser.parse_args() if args.step not in ['deliver', 'parse'] and args.path is not None: parser.error('Too many arguments provided') if args.step in ['deliver', 'parse'] and args.path is None: parser.error('Missing path argument for step ' + args.step) pvn = Pyven(args.step, args.verbose, args.warning_as_error, args.pym, args.release, args.overwrite, arguments={'path': args.path}, nb_lines=args.nb_lines, nb_threads=args.nb_threads) try: ok = True if pvn.step == 'aggregate' and not args.display: pvn.report(args.report_style) if pvn.step == 'init': ok = pvn.init() else: ok = pvn.process() if not ok: raise PyvenException('Pyven build failed') except PyvenException as e: for msg in e.args: Logger.get().error(msg) sys.exit(1) finally: if pvn.step not in ['aggregate']: pvn.report(args.report_style) if args.display: pvn.display() toc = time.time() Logger.get().info('Total process time : ' + str(round(toc - tic, 3)) + ' seconds')
def basename(self): if self.file is not None: return os.path.basename(self.file) raise PyvenException('Unknown artifact location : ' + self.format_name())