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")
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")
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
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')
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
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
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
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
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')
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')
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
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()
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()
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
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
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
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
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
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
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
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")
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')
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')
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
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
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
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
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
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')
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
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
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
def add_configuration_error(cls, msg): add_configuration_error(cls.name.lower(), msg) LOGGER.warning(msg)
def test_error(self): add_configuration_error("Test error", "FOOOOOOOOOOOOOO") response = self.client.get(reverse("admin-performance")) self.assertContains(response, "FOOOOOOOOOOOOOO")