Exemplo n.º 1
0
 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')
Exemplo n.º 2
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
Exemplo n.º 3
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")
Exemplo n.º 4
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')
Exemplo n.º 5
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')
Exemplo n.º 6
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(),
        )
        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
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 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")
Exemplo n.º 10
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()
Exemplo n.º 11
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()
Exemplo n.º 12
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
Exemplo n.º 13
0
    def load_data(self):
        result = super().load_data()

        for fileformat in list(result.values()):
            error_name = "File format: {0}".format(fileformat.format_id)
            delete_configuration_error(error_name)
            try:
                fileformat.get_class()
            except (AttributeError, ImportError) as error:
                result.pop(fileformat.format_id)
                self.errors[fileformat.format_id] = str(error)

        return result
Exemplo n.º 14
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)
            delete_configuration_error(error_name)
            try:
                fileformat.get_class()
            except (AttributeError, ImportError) as error:
                result.pop(fileformat.format_id)
                if fileformat.format_id != 'rc' or not six.PY3:
                    self.errors[fileformat.format_id] = str(error)

        return result
Exemplo n.º 15
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
Exemplo n.º 16
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
Exemplo n.º 17
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:
            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
Exemplo n.º 18
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:
            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
Exemplo n.º 19
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
     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
Exemplo n.º 20
0
Arquivo: gpg.py Projeto: nijel/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:
        add_configuration_error('GPG key generating', force_text(exc))
        return None
Exemplo n.º 21
0
Arquivo: gpg.py Projeto: nijel/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:
        if not silent:
            add_configuration_error('GPG key listing', force_text(exc))
        return None
Exemplo n.º 22
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
     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
Exemplo n.º 23
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
Exemplo n.º 24
0
    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')
Exemplo n.º 25
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
            delete_configuration_error('GPG key listing')
            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
Exemplo n.º 26
0
Arquivo: gpg.py Projeto: nijel/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
Exemplo n.º 27
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
            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
Exemplo n.º 28
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(),
        )
        delete_configuration_error('GPG key generating')
        return get_gpg_key()
    except (subprocess.CalledProcessError, OSError) as exc:
        add_configuration_error('GPG key generating', force_text(exc))
        return None