def update_project_info(project_info_path, version): if not isinstance(version, VersionNumber): version = VersionNumber(version) if project_info_path is None or not os.path.exists(project_info_path): return False project_info_content = open(project_info_path, 'rb').read() try: project_info_content = project_info_content.decode() except UnicodeError: # in case the default encoding is ascii project_info_content = project_info_content.decode('utf-8') # Set version in project info file # It needs to have a version with at least 3 # numbers if len(version) < 3: version.resize(3) if project_info_path.endswith('.cmake'): pattern = re.compile( r'BRAINVISA_PACKAGE_VERSION_MAJOR.+' r'BRAINVISA_PACKAGE_VERSION_PATCH \d+', re.DOTALL) project_info_content_new = pattern.sub( 'BRAINVISA_PACKAGE_VERSION_MAJOR ' + str(version[0]) + ' )\n' + 'set( BRAINVISA_PACKAGE_VERSION_MINOR ' + str(version[1]) + ' )\n' + 'set( BRAINVISA_PACKAGE_VERSION_PATCH ' + str(version[2]), project_info_content) elif project_info_path.endswith('.py'): pattern = re.compile(r'version_major.+\nversion_micro\s*=\s*\d+', re.DOTALL) project_info_content_new = pattern.sub( 'version_major = ' + str(version[0]) + '\n' + 'version_minor = ' + str(version[1]) + '\n' + 'version_micro = ' + str(version[2]), project_info_content) if project_info_content != project_info_content_new: #print(project_info_content_new) # Write new project info content to file # and commit local changes to the branch f = open(project_info_path, "w") f.write(project_info_content_new) f.close() return True return False
def parse_project_info_python(path, version_format=version_format_unconstrained): """Parses an info.py file @type path: string @param path: The path of the info.py file @rtype: tuple @return: A tuple that contains project name, component name and version """ d = {} version = VersionNumber('1.0.0', format=version_format) with open(path) as f: exec(compile(f.read(), path, 'exec'), d, d) for var in ('NAME', 'version_major', 'version_minor', 'version_micro'): if var not in d: raise KeyError('Variable %s missing in info file %s' % (var, path)) project = component = d['NAME'] if len(version) > 0: version[0] = d['version_major'] if len(version) > 1: version[1] = d['version_minor'] if len(version) > 2: version[2] = d['version_micro'] build_model = d.get('brainvisa_build_model') return (project, component, version, build_model)
def branch_version_inc(self, branch_type, version): """ Increments the version for a specified branch type. If the branch_type is: - BranchType.TRUNK => the version is incremented at the major position (position 0). i.e. '1.2.3' => '2.0.0'. If the version to increment is None, '1' is returned. - BranchType.BUG_FIX => the version is incremented at the minor position (position 1). i.e. '1.2.3' => '1.3.0'. If the version to increment is None, '1.0' is returned. - BranchType.RELEASE => the version is incremented at the micro position (position 2). i.e. 1.2.3 => 1.2.4. If the version to increment is None, '1.0.0' is returned. @type branch_type: BranchType @param branch_type: The type of the branch to increment version for. @type version: string @param version: The version to increment. @rtype: string @return: The incremented version for the branch type. """ version = VersionNumber(version, format=self._version_format) if branch_type == BranchType.TRUNK: position = 0 elif branch_type == BranchType.BUG_FIX: position = 1 elif branch_type == BranchType.RELEASE: position = 2 else: raise RuntimeError('Unable to increment version:', version, 'for unknown branch type:', branch_type) return version.increment(position=position)
def parse_project_info_cmake(path, version_format=version_format_unconstrained): """Parses a project_info.cmake file @type path: string @param path: The path of the project_info.cmake file @rtype: tuple @return: A tuple that contains project name, component name and version """ project = None component = None version = VersionNumber('1.0.0', format=version_format) build_model = None p = re.compile(r'\s*set\(\s*([^ \t]*)\s*(.*[^ \t])\s*\)') with open(path, 'rb') as f: for line in f: try: line = line.decode() except UnicodeError: line = line.decode( 'utf-8') # in case the default encoding is ascii match = p.match(line) if match: variable, value = match.groups() if variable == 'BRAINVISA_PACKAGE_NAME': component = value elif variable == 'BRAINVISA_PACKAGE_MAIN_PROJECT': project = value elif variable == 'BRAINVISA_PACKAGE_VERSION_MAJOR' and len( version) > 0: version[0] = value elif variable == 'BRAINVISA_PACKAGE_VERSION_MINOR' and len( version) > 1: version[1] = value elif variable == 'BRAINVISA_PACKAGE_VERSION_PATCH' and len( version) > 2: version[2] = value elif variable == 'BRAINVISA_BUILD_MODEL': build_model = value return (project, component, version, build_model)
def branch_version_is_max(self, branch_type, version): """ Check that a version is the maximum version for a BranchType. @type: string @param branch_type: The BranchType to check maximum version. @type: string @param version: The version to check. @rtype: bool @return: A boolean that is True if the version is the maximum for the branch_type, False otherwise. When no branch version exists, version is always the maximum version. """ branch_version_max, branch_name = self.branch_version_max(branch_type) # When branch_info or branch_info[0] are None, it means that no version # was found for the specified branch_type. So the given version is # necessarly the maximum version. return (branch_version_max < VersionNumber( version, format=self._version_format))
def branch_version_max(self, branch_type=BranchType.TRUNK, version_patterns=['*']): """ Maximum version for a BranchType and a list of version patterns. @type: string @param branch_type: The BranchType to get maximum version for. @type: list @param version_patterns: The version patterns to match [Default: [ '*' ] ]. @rtype: string @return: A tuple that contains the maximum version and the branch name for the branch type and version patterns. """ branch_versions = self.branch_versions( branch_type=branch_type, version_patterns=version_patterns) if (len(branch_versions) > 0): m = max(branch_versions.keys()) return (m, branch_versions[m]) return (VersionNumber(None, format=self._version_format), None)
s = os.path.join(p, sys.argv[0]) if os.path.exists(s): this_script = s break if this_script: this_script = os.path.abspath(this_script) python_modules = os.path.join( os.path.dirname(os.path.dirname(this_script)), 'python') if os.path.isdir(python_modules): sys.path.insert(0, python_modules) if this_script: cmake_root = os.path.join(os.path.dirname(this_script), '..', 'share', 'brainvisa-cmake-%s' % str(VersionNumber( brainvisa_cmake_version, version_format_short)), 'cmake') class ComponentsConfigParser(brainvisa.maker.configuration.DirectorySection): def __init__(self, directory, configuration): super(ComponentsConfigParser, self).__init__() self.configuration = configuration self.directory = directory self.configurationLines = [] self.projects = set() self.components = {} self._configuration_lines_processed = False