示例#1
0
 def test_version_mismatch(self):
     """Test handling of configuration files from different rosrepo versions"""
     os.makedirs(os.path.join(self.wsdir, ".rosrepo"))
     cfg_file = os.path.join(self.wsdir, ".rosrepo", "config")
     with open(cfg_file, "w") as f:
         f.write("version: %s" % rosrepo_version)
     cfg = Config(self.wsdir)
     self.assertEqual(cfg.get("version"), rosrepo_version)
     with open(cfg_file, "w") as f:
         f.write("version: 3.0.0a0")
     cfg = Config(self.wsdir)
     self.assertEqual(cfg.get("version"), rosrepo_version)
     # revisions may change without affecting config compatibility
     v = StrictVersion(rosrepo_version)
     v.version = tuple([v.version[0], v.version[1], v.version[2] + 1])
     with open(cfg_file, "w") as f:
         f.write('version: "%s"' % str(v))
     cfg = Config(self.wsdir)
     self.assertEqual(cfg.get("version"), str(v))
     # major or minor version number change means incompatible configurations
     v.version = tuple([v.version[0], v.version[1] + 1, 0])
     with open(cfg_file, "w") as f:
         f.write('version: "%s"' % str(v))
     self.assertRaises(ConfigError, lambda: Config(self.wsdir))
     v.version = tuple([v.version[0] + 1, 0, 0])
     with open(cfg_file, "w") as f:
         f.write('version: "%s"' % str(v))
     self.assertRaises(ConfigError, lambda: Config(self.wsdir))
示例#2
0
    def test_update_testsuites(self):

        v = StrictVersion(self.testsuites['MTBC/test'].version)
        # load by full name
        testsuites = {}
        update_testsuites(testsuites,
                {'MTBC/test': str(v)},
                self.testsuite_paths
            )
        assert testsuites.keys() == ['MTBC/test']
        # load by short name
        update_testsuites(testsuites,
                {'test': str(v)},
                self.testsuite_paths
            )
        assert set(testsuites.keys()) == set(['MTBC/test', 'test'])
        assert testsuites['test'] == testsuites['MTBC/test']

        # load compatible
        vv = list(v.version)
        vv[1] -= 1
        v.version = vv
        update_testsuites(testsuites,
                {'test': str(v)},
                self.testsuite_paths
            )
        assert set(testsuites.keys()) == set(['MTBC/test', 'test'])

        # load incompatbile 1/2
        vv[1] += 2
        v.version = vv
        try:
            update_testsuites(testsuites,
                    {'test': str(v)},
                    self.testsuite_paths
                )
            assert False, 'future minor version specified; should fail'
        except TestsuiteVersionConflictException:
            pass

        # load incompatbile 1/2
        vv[1] -= 1
        vv[0] -= 1
        v.version = vv
        try:
            update_testsuites(testsuites,
                    {'test': str(v)},
                    self.testsuite_paths
                )
            assert False, 'different major version specified; should fail'
        except TestsuiteVersionConflictException:
            pass
示例#3
0
def read_git_version():
    try:
        proc = subprocess.Popen(
            ('git', 'describe', '--long', '--match', 'v[0-9]*.*'),
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        data, _ = proc.communicate()
        if proc.returncode:
            return None, None
        ver = data.decode('utf-8').splitlines()[0].strip()
    except:
        return None, None

    if not ver:
        return None, None
    m = re.search(_GIT_DESCRIPTION_RE, ver)
    if not m:
        sys.stderr.write('version: git description (%s) is invalid, '
                         'ignoring\n' % ver)
        return None, None

    commits = int(m.group('commits'))
    ver = StrictVersion(m.group('ver'))
    if not commits:
        return ver, commits
    else:
        if len(ver.version) == 2:
            ver.version += (0, )
        ver.version = (ver.version[0], ver.version[1],
                       ver.version[2] + commits)
        return ver, commits
示例#4
0
    def run(self):
        if self.set:
            newver = str(self.set)
        else:
            try:
                oldver = self.distribution.metadata.version
                oldver = StrictVersion(oldver)
            except ValueError as err:
                print("Error: setup.py", err, file=sys.stderr)
                sys.exit(errno.EINVAL)

            major, minor, patch = oldver.version
            pre = oldver.prerelease

            if self.alpha:
                if pre is None or pre[0] != 'a':
                    pre = ('a', 0)
                else:
                    pre = (pre[0], pre[1] + 1)
            elif self.beta:
                if pre is None or pre[0] != 'b':
                    pre = ('b', 0)
                else:
                    pre = (pre[0], pre[1] + 1)
            elif self.release:
                pre = None
            elif self.patch:
                patch = patch + 1
                pre = None
            elif self.minor:
                minor = minor + 1
                patch = 0
                pre = None
            elif self.major:
                major = major + 1
                minor = 0
                patch = 0
                pre = None
            else:
                return
            newver = StrictVersion()
            newver.version = (major, minor, patch)
            newver.prerelease = pre
            newver = str(newver)

        for dirpath, dirnames, filenames in os.walk(os.curdir):
            for filename in (f for f in filenames if os.path.splitext(f)[1] == '.py'):
                inpath = os.path.join(dirpath, filename)
                outpath = inpath + '.tmp'
                with open(inpath) as fin, open(outpath, 'w') as fout:
                    for line in fin:
                        if line.startswith("__version__"):
                            line = "__version__ = '{0}'\n".format(newver)
                        fout.write(line)
                shutil.copystat(inpath, outpath)
                os.replace(outpath, inpath)
示例#5
0
def strict_current_version() -> StrictVersion:
    try:
        return StrictVersion(VERSION)
    except ValueError:
        if ".dev" not in VERSION:
            raise
        result = StrictVersion(VERSION.split(".dev")[0])
        result.version = (result.version[0], result.version[1],
                          result.version[2] - 1)
        return result
示例#6
0
def load_config(filename):
    """
        Load the configuration file and test if version is supported.
    """
    (_, ext) = os.path.splitext(filename)
    config = None
    if ext == '.json':
        import json
        with open(filename, 'rb') as fds:
            config = json.load(fds)
    elif ext == '.yml':
        import yaml
        with open(filename, 'rb') as fds:
            config = yaml.safe_load(fds)
    else:
        logging.error('Config file extension not recognized: %s', filename)
        sys.exit(1)

    file_version_string = config.get('header', {}).get('version', None)

    if file_version_string is None:
        logging.error('Version missing: %s', filename)
        sys.exit(1)

    try:
        if not isinstance(file_version_string, str):
            logging.error('Version has to be a string: %s', filename)
            sys.exit(1)

        file_version = StrictVersion()
        file_version.parse(file_version_string)
        kas_version = StrictVersion()
        kas_version.parse(__version__)
        lower_version = StrictVersion()
        lower_version.parse(__compatible_version__)

        # Remove patch version, because we provide limited forwards
        # compatibility:
        if file_version.version[2] > 0:
            file_version.prerelease = None
            file_version.version = tuple(list(file_version.version[:2]) + [0])

        if file_version < lower_version or kas_version < file_version:
            logging.error(
                'This version of kas is compatible with version %s '
                'to %s, file has version %s: %s', lower_version, kas_version,
                file_version, filename)
            sys.exit(1)
    except ValueError:
        logging.exception('Not expected version format: %s', filename)
        raise

    return config
def load_translations(lang, version=1, commcare_version=None):
    # pt => por: hack for backwards compatibility
    if lang == 'pt':
        lang = 'por'

    try:
        str(lang)
    except UnicodeEncodeError:
        return {}

    paths_to_try = []
    if commcare_version == 'latest':
        files = listdir(normpath(join(__file__, "../historical-translations-by-version/")))
        if len(files):
            files.sort()
            files.reverse()
            paths_to_try.append(
                '../historical-translations-by-version/{file}'
                .format(file=files[0])
            )
            commcare_version = None
    elif commcare_version:
        try:
            commcare_version = StrictVersion(commcare_version)
        except ValueError:
            commcare_version = None
    if version == 2 and lang == 'en' and commcare_version:
        # the earliest version we have is 2.23
        if commcare_version < StrictVersion('2.23'):
            commcare_version = StrictVersion('2.23')
        major, minor, bugfix = commcare_version.version
        while bugfix >= 0:
            commcare_version.version = major, minor, bugfix
            paths_to_try.append(
                '../historical-translations-by-version/{commcare_version}-messages_{lang}-{version}.txt'
                .format(commcare_version=commcare_version, lang=lang, version=version)
            )
            bugfix -= 1

    while version:
        paths_to_try.append('../messages_{lang}-{version}.txt'
                            .format(lang=lang, version=version))
        version -= 1

    for rel_path in paths_to_try:
        path = normpath(join(__file__, rel_path))
        try:
            with open(path, encoding='utf-8') as f:
                return load(f)
        except IOError:
            pass
    return {}
示例#8
0
    def advance_patch(version: StrictVersion, by: int = 1) -> StrictVersion:
        """
        Advances patch version number 
        :param version: version to modify
        :param by: step to advance
        :return: StrictVersion
        """
        new_version = StrictVersion(str(version))
        version_modify = list(new_version.version)
        version_modify[2] = version_modify[2] + by
        new_version.version = tuple(version_modify)

        return new_version
示例#9
0
    def advance_major(version: StrictVersion, by: int = 1) -> StrictVersion:
        """
        Advance major version number
        :param version: version to modify
        :param by: step to advance
        :return: StrictVersion
        """
        new_version = StrictVersion(str(version))
        version_modify = list(new_version.version)
        version_modify[0] = version_modify[0] + by
        version_modify[1] = 0
        version_modify[2] = 0
        new_version.version = tuple(version_modify)

        return new_version
示例#10
0
def parse_version(vstring):
    """
    StrictVersion / LooseVersion decorator method
    @type   vstring:    str
    @return:    StrictVersion if possible, otherwise LooseVersion
    @rtype:     StrictVersion or LooseVersion
    """
    try:
        version = StrictVersion(vstring)
    except ValueError:
        logging.getLogger('ipvs.common.debug').info('Strict parsing failed, falling back to LooseVersion instead')
        version = LooseVersion(vstring)
        version.version = tuple(version.version)

    return version
示例#11
0
def parse_version(vstring):
    """
    StrictVersion / LooseVersion decorator method
    @type   vstring:    str
    @return:    StrictVersion if possible, otherwise LooseVersion
    @rtype:     StrictVersion or LooseVersion
    """
    try:
        version = StrictVersion(vstring)
    except ValueError:
        logging.getLogger('ipvs.common.debug').info(
            'Strict parsing failed, falling back to LooseVersion instead')
        version = LooseVersion(vstring)
        version.version = tuple(version.version)

    return version