コード例 #1
0
    def ready(self):
        super().ready()
        register(check_vcs)
        home = data_dir("home")
        if not os.path.exists(home):
            os.makedirs(home)
        # Configure merge driver for Gettext PO
        # We need to do this behind lock to avoid errors when servers
        # start in parallel
        lockfile = FileLock(os.path.join(home, "gitlock"))
        with lockfile:
            try:
                GitRepository.global_setup()
                delete_configuration_error("Git global setup")
            except RepositoryException as error:
                add_configuration_error(
                    "Git global setup",
                    "Failed to do git setup: {0}".format(error))

        # Use it for *.po by default
        configdir = os.path.join(home, ".config", "git")
        configfile = os.path.join(configdir, "attributes")
        if not os.path.exists(configfile):
            if not os.path.exists(configdir):
                os.makedirs(configdir)
            with open(configfile, "w") as handle:
                handle.write("*.po merge=weblate-merge-gettext-po\n")
コード例 #2
0
 def test_error(self):
     add_configuration_error("Test error", "FOOOOOOOOOOOOOO")
     response = self.client.get(reverse("manage-performance"))
     self.assertContains(response, "FOOOOOOOOOOOOOO")
     delete_configuration_error("Test error")
     response = self.client.get(reverse("manage-performance"))
     self.assertNotContains(response, "FOOOOOOOOOOOOOO")
コード例 #3
0
 def is_supported(cls):
     """
     Checks whether this VCS backend is supported.
     """
     if cls._is_supported is not None:
         return cls._is_supported
     try:
         version = cls.get_version()
     except OSError:
         cls._is_supported = False
         return False
     if cls.req_version is None:
         cls._is_supported = True
     elif LooseVersion(version) >= LooseVersion(cls.req_version):
         cls._is_supported = True
     else:
         cls._is_supported = False
         add_configuration_error(
             cls.name.lower(),
             '{0} version is too old, please upgrade to {1}.'.format(
                 cls.name,
                 cls.req_version
             )
         )
     return cls._is_supported
コード例 #4
0
    def ready(self):
        home = data_dir('home')
        if not os.path.exists(home):
            os.makedirs(home)
        # Configure merge driver for Gettext PO
        # We need to do this behind lock to avoid errors when servers
        # start in parallel
        lockfile = FileLock(os.path.join(home, 'gitlock'))
        with lockfile:
            try:
                GitRepository.global_setup()
                delete_configuration_error('Git global setup')
            except RepositoryException as error:
                add_configuration_error(
                    'Git global setup',
                    'Failed to do git setup: {0}'.format(error))

        # Use it for *.po by default
        configdir = os.path.join(home, '.config', 'git')
        configfile = os.path.join(configdir, 'attributes')
        if not os.path.exists(configfile):
            if not os.path.exists(configdir):
                os.makedirs(configdir)
            with open(configfile, 'w') as handle:
                handle.write('*.po merge=weblate-merge-gettext-po\n')
コード例 #5
0
ファイル: gpg.py プロジェクト: bonomali/weblate
def generate_gpg_key():
    try:
        subprocess.check_output(
            [
                "gpg",
                "--batch",
                "--pinentry-mode",
                "loopback",
                "--passphrase",
                "",
                "--quick-generate-key",
                settings.WEBLATE_GPG_IDENTITY,
                settings.WEBLATE_GPG_ALGO,
                "default",
                "never",
            ],
            stderr=subprocess.STDOUT,
            env=get_clean_env(),
        )
        delete_configuration_error("GPG key generating")
        return get_gpg_key()
    except (subprocess.CalledProcessError, OSError) as exc:
        report_error(exc, prefix="GPG key generating")
        add_configuration_error("GPG key generating", force_text(exc))
        return None
コード例 #6
0
def get_gpg_key(silent=False):
    try:
        result = subprocess.run(
            [
                "gpg",
                "--batch",
                "--with-colons",
                "--list-secret-keys",
                settings.WEBLATE_GPG_IDENTITY,
            ],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            env=get_clean_env(),
            universal_newlines=True,
            check=True,
        )
        for line in result.stdout.splitlines():
            if not line.startswith("fpr:"):
                continue
            delete_configuration_error("GPG key listing")
            return line.split(":")[9]
        return None
    except (subprocess.CalledProcessError, OSError) as error:
        report_error(cause="GPG key listing")
        if not silent:
            add_configuration_error("GPG key listing", force_str(error))
        return None
コード例 #7
0
 def is_supported(cls):
     """Check whether this VCS backend is supported."""
     if cls._is_supported is not None:
         return cls._is_supported
     try:
         version = cls.get_version()
     except (OSError, RepositoryException):
         cls._is_supported = False
         return False
     try:
         if cls.req_version is None or LooseVersion(version) >= LooseVersion(
             cls.req_version
         ):
             cls._is_supported = True
             delete_configuration_error(cls.name.lower())
             return True
     except Exception as error:
         add_configuration_error(
             cls.name.lower(),
             "{0} version check failed (version {1}, required {2}): {3}".format(
                 cls.name, version, cls.req_version, error
             ),
         )
     else:
         add_configuration_error(
             cls.name.lower(),
             "{0} version is too old, please upgrade to {1}.".format(
                 cls.name, cls.req_version
             ),
         )
     cls._is_supported = False
     return False
コード例 #8
0
ファイル: vcs.py プロジェクト: Saectar/weblate
 def is_supported(cls):
     """
     Checks whether this VCS backend is supported.
     """
     if cls._is_supported is not None:
         return cls._is_supported
     try:
         version = cls.get_version()
     except OSError:
         cls._is_supported = False
         return False
     if cls.req_version is None:
         cls._is_supported = True
     elif LooseVersion(version) >= cls.req_version:
         cls._is_supported = True
     else:
         cls._is_supported = False
         add_configuration_error(
             cls.name.lower(),
             '{0} version is too old, please upgrade to {1}.'.format(
                 cls.name,
                 cls.req_version
             )
         )
     return cls._is_supported
コード例 #9
0
 def test_error(self):
     add_configuration_error('Test error', 'FOOOOOOOOOOOOOO')
     response = self.client.get(reverse('manage-performance'))
     self.assertContains(response, 'FOOOOOOOOOOOOOO')
     delete_configuration_error('Test error')
     response = self.client.get(reverse('manage-performance'))
     self.assertNotContains(response, 'FOOOOOOOOOOOOOO')
コード例 #10
0
ファイル: tests.py プロジェクト: dekoza/weblate
 def test_error(self):
     add_configuration_error('Test error', 'FOOOOOOOOOOOOOO')
     response = self.client.get(reverse('admin:performance'))
     self.assertContains(response, 'FOOOOOOOOOOOOOO')
     delete_configuration_error('Test error')
     response = self.client.get(reverse('admin:performance'))
     self.assertNotContains(response, 'FOOOOOOOOOOOOOO')
コード例 #11
0
def generate_gpg_key():
    try:
        subprocess.run(
            [
                "gpg",
                "--batch",
                "--pinentry-mode",
                "loopback",
                "--passphrase",
                "",
                "--quick-generate-key",
                settings.WEBLATE_GPG_IDENTITY,
                settings.WEBLATE_GPG_ALGO,
                "default",
                "never",
            ],
            env=get_clean_env(),
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            universal_newlines=True,
            check=True,
        )
        delete_configuration_error("GPG key generating")
        return get_gpg_key()
    except (subprocess.CalledProcessError, OSError) as exc:
        report_error(cause="GPG key generating")
        add_configuration_error("GPG key generating", force_str(exc))
        return None
コード例 #12
0
 def test_configuration_health_check(self):
     add_configuration_error("TEST", "Message", True)
     add_configuration_error("TEST2", "Message", True)
     configuration_health_check(False)
     self.assertEqual(ConfigurationError.objects.count(), 2)
     delete_configuration_error("TEST2", True)
     configuration_health_check(False)
     self.assertEqual(ConfigurationError.objects.count(), 1)
     configuration_health_check()
コード例 #13
0
ファイル: tests.py プロジェクト: dekoza/weblate
 def test_configuration_health_check(self):
     add_configuration_error('TEST', 'Message', True)
     add_configuration_error('TEST2', 'Message', True)
     configuration_health_check(False)
     self.assertEqual(ConfigurationError.objects.count(), 2)
     delete_configuration_error('TEST2', True)
     configuration_health_check(False)
     self.assertEqual(ConfigurationError.objects.count(), 1)
     configuration_health_check()
コード例 #14
0
ファイル: formats.py プロジェクト: nblock/weblate
def register_fileformat(fileformat):
    """
    Registers fileformat in dictionary.
    """
    try:
        fileformat.get_class()
        FILE_FORMATS[fileformat.format_id] = fileformat
    except (AttributeError, ImportError):
        add_configuration_error("File format: {0}".format(fileformat.format_id), traceback.format_exc())
    return fileformat
コード例 #15
0
ファイル: formats.py プロジェクト: dhodhala88/Bosch1
def register_fileformat(fileformat):
    '''
    Registers fileformat in dictionary.
    '''
    try:
        fileformat.get_class()
        FILE_FORMATS[fileformat.format_id] = fileformat
    except (AttributeError, ImportError):
        add_configuration_error(
            'File format: {0}'.format(fileformat.format_id),
            traceback.format_exc())
    return fileformat
コード例 #16
0
def register_fileformat(fileformat):
    """Register fileformat in dictionary."""
    try:
        fileformat.get_class()
        FILE_FORMATS[fileformat.format_id] = fileformat
        for autoload in fileformat.autoload:
            FILE_DETECT.append((autoload, fileformat))
    except (AttributeError, ImportError):
        add_configuration_error(
            'File format: {0}'.format(fileformat.format_id),
            traceback.format_exc())
    return fileformat
コード例 #17
0
    def load_data(self):
        result = super(FileFormatLoader, self).load_data()

        for fileformat in list(result.values()):
            error_name = 'File format: {0}'.format(fileformat.format_id)
            try:
                fileformat.get_class()
                delete_configuration_error(error_name)
            except (AttributeError, ImportError):
                add_configuration_error(error_name, traceback.format_exc())
                result.pop(fileformat.format_id)

        return result
コード例 #18
0
ファイル: formats.py プロジェクト: saily/weblate
def register_fileformat(fileformat):
    """Register fileformat in dictionary."""
    try:
        fileformat.get_class()
        FILE_FORMATS[fileformat.format_id] = fileformat
        for autoload in fileformat.autoload:
            FILE_DETECT.append((autoload, fileformat))
    except (AttributeError, ImportError):
        add_configuration_error(
            'File format: {0}'.format(fileformat.format_id),
            traceback.format_exc()
        )
    return fileformat
コード例 #19
0
ファイル: models.py プロジェクト: daleathan/weblate
    def load_data(self):
        result = super(FileFormatLoader, self).load_data()

        for fileformat in list(result.values()):
            try:
                fileformat.get_class()
            except (AttributeError, ImportError):
                add_configuration_error(
                    'File format: {0}'.format(fileformat.format_id),
                    traceback.format_exc()
                )
                result.pop(fileformat.format_id)

        return result
コード例 #20
0
ファイル: models.py プロジェクト: dekoza/weblate
    def load_data(self):
        result = super(FileFormatLoader, self).load_data()

        for fileformat in list(result.values()):
            error_name = 'File format: {0}'.format(fileformat.format_id)
            try:
                fileformat.get_class()
                delete_configuration_error(error_name)
            except (AttributeError, ImportError) as error:
                result.pop(fileformat.format_id)
                if fileformat.format_id == 'rc' and six.PY3:
                    continue
                add_configuration_error(error_name, str(error))

        return result
コード例 #21
0
ファイル: apps.py プロジェクト: nijel/weblate
    def ready(self):
        # Configure merge driver for Gettext PO
        try:
            GitRepository.global_setup()
        except RepositoryException as error:
            add_configuration_error("Git global setup", "Failed to do git setup: {0}".format(error))

        # Use it for *.po by default
        configdir = os.path.join(data_dir("home"), ".config", "git")
        configfile = os.path.join(configdir, "attributes")
        if not os.path.exists(configfile):
            if not os.path.exists(configdir):
                os.makedirs(configdir)
            with open(configfile, "w") as handle:
                handle.write("*.po merge=weblate-merge-gettext-po\n")
コード例 #22
0
    def load_data(self):
        result = super(FileFormatLoader, self).load_data()

        for fileformat in list(result.values()):
            error_name = 'File format: {0}'.format(fileformat.format_id)
            try:
                fileformat.get_class()
                delete_configuration_error(error_name)
            except (AttributeError, ImportError) as error:
                result.pop(fileformat.format_id)
                if fileformat.format_id == 'rc' and six.PY3:
                    continue
                add_configuration_error(error_name, str(error))

        return result
コード例 #23
0
ファイル: apps.py プロジェクト: nleduc/weblate
    def ready(self):
        # Configure merge driver for Gettext PO
        try:
            GitRepository.global_setup()
        except RepositoryException as error:
            add_configuration_error(
                'Git global setup',
                'Failed to do git setup: {0}'.format(error))

        # Use it for *.po by default
        configdir = os.path.join(data_dir('home'), '.config', 'git')
        configfile = os.path.join(configdir, 'attributes')
        if not os.path.exists(configfile):
            if not os.path.exists(configdir):
                os.makedirs(configdir)
            with open(configfile, 'w') as handle:
                handle.write('*.po merge=weblate-merge-gettext-po\n')
コード例 #24
0
ファイル: apps.py プロジェクト: saily/weblate
    def ready(self):
        # Configure merge driver for Gettext PO
        try:
            GitRepository.global_setup()
        except RepositoryException as error:
            add_configuration_error(
                'Git global setup',
                'Failed to do git setup: {0}'.format(error)
            )

        # Use it for *.po by default
        configdir = os.path.join(data_dir('home'), '.config', 'git')
        configfile = os.path.join(configdir, 'attributes')
        if not os.path.exists(configfile):
            if not os.path.exists(configdir):
                os.makedirs(configdir)
            with open(configfile, 'w') as handle:
                handle.write('*.po merge=weblate-merge-gettext-po\n')
コード例 #25
0
ファイル: gpg.py プロジェクト: tdelmas/weblate
def get_gpg_public_key():
    key = get_gpg_sign_key()
    if key is None:
        return None
    data = cache.get('gpg-key-public')
    if not data:
        try:
            data = subprocess.check_output(
                ['gpg', '--batch', '-armor', '--export', key],
                stderr=subprocess.STDOUT,
                env=get_clean_env(),
            ).decode('utf-8')
            cache.set('gpg-key-public', data, 7 * 86400)
            delete_configuration_error('GPG key public')
        except (subprocess.CalledProcessError, OSError) as exc:
            add_configuration_error('GPG key public', force_text(exc))
            return None
    return data
コード例 #26
0
ファイル: gpg.py プロジェクト: bonomali/weblate
def get_gpg_public_key():
    key = get_gpg_sign_key()
    if key is None:
        return None
    data = cache.get("gpg-key-public")
    if not data:
        try:
            data = subprocess.check_output(
                ["gpg", "--batch", "-armor", "--export", key],
                stderr=subprocess.STDOUT,
                env=get_clean_env(),
            ).decode("utf-8")
            cache.set("gpg-key-public", data, 7 * 86400)
            delete_configuration_error("GPG key public")
        except (subprocess.CalledProcessError, OSError) as exc:
            report_error(exc, prefix="GPG key public")
            add_configuration_error("GPG key public", force_text(exc))
            return None
    return data
コード例 #27
0
ファイル: gpg.py プロジェクト: daleathan/weblate
def generate_gpg_key():
    try:
        subprocess.check_output(
            [
                'gpg',
                '--batch',
                '--pinentry-mode', 'loopback',
                '--passphrase', '',
                '--quick-generate-key',
                settings.WEBLATE_GPG_IDENTITY,
                settings.WEBLATE_GPG_ALGO,
                'default', 'never',
            ],
            stderr=subprocess.STDOUT,
            env=get_clean_env(),
        )
        return get_gpg_key()
    except (subprocess.CalledProcessError, OSError) as exc:
        add_configuration_error('GPG key generating', force_text(exc))
        return None
コード例 #28
0
ファイル: gpg.py プロジェクト: daleathan/weblate
def get_gpg_key(silent=False):
    try:
        output = subprocess.check_output(
            [
                'gpg',
                '--batch',
                '--with-colons',
                '--list-secret-keys',
                settings.WEBLATE_GPG_IDENTITY,
            ],
            stderr=subprocess.STDOUT,
            env=get_clean_env(),
        ).decode('utf-8')
        for line in output.splitlines():
            if not line.startswith('fpr:'):
                continue
            return line.split(':')[9]
        return None
    except (subprocess.CalledProcessError, OSError) as exc:
        if not silent:
            add_configuration_error('GPG key listing', force_text(exc))
        return None
コード例 #29
0
def get_gpg_key(silent=False):
    try:
        output = subprocess.check_output(
            [
                'gpg',
                '--batch',
                '--with-colons',
                '--list-secret-keys',
                settings.WEBLATE_GPG_IDENTITY,
            ],
            stderr=subprocess.STDOUT,
            env=get_clean_env(),
        ).decode('utf-8')
        for line in output.splitlines():
            if not line.startswith('fpr:'):
                continue
            return line.split(':')[9]
        return None
    except (subprocess.CalledProcessError, OSError) as exc:
        if not silent:
            add_configuration_error('GPG key listing', force_text(exc))
        return None
コード例 #30
0
ファイル: gpg.py プロジェクト: daleathan/weblate
def get_gpg_public_key():
    key = get_gpg_sign_key()
    if key is None:
        return None
    data = cache.get('gpg-key-public')
    if not data:
        try:
            data = subprocess.check_output(
                [
                    'gpg',
                    '--batch',
                    '-armor',
                    '--export',
                    key,
                ],
                stderr=subprocess.STDOUT,
                env=get_clean_env(),
            ).decode('utf-8')
            cache.set('gpg-key-public', data, 7 * 86400)
        except (subprocess.CalledProcessError, OSError) as exc:
            add_configuration_error('GPG key public', force_text(exc))
            return None
    return data
コード例 #31
0
ファイル: apps.py プロジェクト: nijel/weblate
    def ready(self):
        # Configure merge driver for Gettext PO
        # We need to do this behind lock to avoid errors when servers
        # start in parallel
        lockfile = FileLock(os.path.join(data_dir('home'), 'gitlock'))
        with lockfile:
            try:
                GitRepository.global_setup()
                delete_configuration_error('Git global setup')
            except RepositoryException as error:
                add_configuration_error(
                    'Git global setup',
                    'Failed to do git setup: {0}'.format(error)
                )

        # Use it for *.po by default
        configdir = os.path.join(data_dir('home'), '.config', 'git')
        configfile = os.path.join(configdir, 'attributes')
        if not os.path.exists(configfile):
            if not os.path.exists(configdir):
                os.makedirs(configdir)
            with open(configfile, 'w') as handle:
                handle.write('*.po merge=weblate-merge-gettext-po\n')
コード例 #32
0
def generate_gpg_key():
    try:
        subprocess.check_output(
            [
                'gpg',
                '--batch',
                '--pinentry-mode',
                'loopback',
                '--passphrase',
                '',
                '--quick-generate-key',
                settings.WEBLATE_GPG_IDENTITY,
                settings.WEBLATE_GPG_ALGO,
                'default',
                'never',
            ],
            stderr=subprocess.STDOUT,
            env=get_clean_env(),
        )
        return get_gpg_key()
    except (subprocess.CalledProcessError, OSError) as exc:
        add_configuration_error('GPG key generating', force_text(exc))
        return None
コード例 #33
0
ファイル: base.py プロジェクト: nijel/weblate
 def is_supported(cls):
     """Check whether this VCS backend is supported."""
     if cls._is_supported is not None:
         return cls._is_supported
     try:
         version = cls.get_version()
     except (OSError, RepositoryException):
         cls._is_supported = False
         return False
     if (cls.req_version is None or
             LooseVersion(version) >= LooseVersion(cls.req_version)):
         cls._is_supported = True
         delete_configuration_error(cls.name.lower())
     else:
         cls._is_supported = False
         add_configuration_error(
             cls.name.lower(),
             '{0} version is too old, please upgrade to {1}.'.format(
                 cls.name,
                 cls.req_version
             )
         )
     return cls._is_supported
コード例 #34
0
def get_gpg_public_key():
    key = get_gpg_sign_key()
    if key is None:
        return None
    data = cache.get("gpg-key-public")
    if not data:
        try:
            result = subprocess.run(
                ["gpg", "--batch", "-armor", "--export", key],
                env=get_clean_env(),
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=True,
                check=True,
            )
            data = result.stdout
            cache.set("gpg-key-public", data, 7 * 86400)
            delete_configuration_error("GPG key public")
        except (subprocess.CalledProcessError, OSError) as error:
            report_error(cause="GPG key public")
            add_configuration_error("GPG key public", force_str(error))
            return None
    return data
コード例 #35
0
ファイル: gpg.py プロジェクト: bonomali/weblate
def get_gpg_key(silent=False):
    try:
        output = subprocess.check_output(
            [
                "gpg",
                "--batch",
                "--with-colons",
                "--list-secret-keys",
                settings.WEBLATE_GPG_IDENTITY,
            ],
            stderr=subprocess.STDOUT,
            env=get_clean_env(),
        ).decode("utf-8")
        for line in output.splitlines():
            if not line.startswith("fpr:"):
                continue
            delete_configuration_error("GPG key listing")
            return line.split(":")[9]
        return None
    except (subprocess.CalledProcessError, OSError) as exc:
        report_error(exc, prefix="GPG key listing")
        if not silent:
            add_configuration_error("GPG key listing", force_text(exc))
        return None
コード例 #36
0
ファイル: base.py プロジェクト: teonomia/weblate
 def add_configuration_error(cls, msg):
     add_configuration_error(cls.name.lower(), msg)
     LOGGER.warning(msg)
コード例 #37
0
ファイル: test_admin.py プロジェクト: beck/weblate
 def test_error(self):
     add_configuration_error("Test error", "FOOOOOOOOOOOOOO")
     response = self.client.get(reverse("admin-performance"))
     self.assertContains(response, "FOOOOOOOOOOOOOO")