def ensure_ssh_dir(): """ Ensures the ssh configuration directory exists. """ ssh_dir = data_dir('ssh') if not os.path.exists(ssh_dir): os.makedirs(ssh_dir)
def ssh_file(filename): """ Generates full path to SSH configuration file. """ return os.path.join( data_dir('ssh'), filename )
def __init__(self): self.index = FileStorage(data_dir('memory')).open_index() self.parser = qparser.QueryParser( 'source', schema=self.index.schema, group=qparser.OrGroup.factory(0.9), termclass=query.FuzzyTerm, ) self.searcher = None self.comparer = Comparer()
def get_wrapper_filename(): """Calculates unique wrapper filename. It is based on template and DATA_DIR settings. """ md5 = hashlib.md5(SSH_WRAPPER_TEMPLATE.encode('utf-8')) md5.update(data_dir('ssh').encode('utf-8')) return ssh_file('ssh-weblate-wrapper-{0}'.format( md5.hexdigest() ))
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() 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_clean_env(extra=None): """ Returns cleaned up environment for subprocess execution. """ environ = { 'LANG': 'en_US.UTF-8', 'HOME': data_dir('home'), } if extra is not None: environ.update(extra) variables = ('PATH', 'LD_LIBRARY_PATH') for var in variables: if var in os.environ: environ[var] = os.environ[var] return environ
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_clean_env(extra=None): """Return cleaned up environment for subprocess execution.""" environ = { 'LANG': 'en_US.UTF-8', 'HOME': data_dir('home'), } if extra is not None: environ.update(extra) variables = ('PATH', 'LD_LIBRARY_PATH') for var in variables: if var in os.environ: environ[var] = os.environ[var] # Python 2 on Windows doesn't handle Unicode objects in environment # even if they can be converted to ASCII string, let's fix it here if six.PY2 and sys.platform == 'win32': return { str(key): str(val) for key, val in environ.items() } return environ
def ssh_file(filename): """Generate full path to SSH configuration file.""" return os.path.join(data_dir('ssh'), filename)
def clean_indexes(): """ Cleans all indexes. """ shutil.rmtree(data_dir('whoosh')) create_index()
import functools import shutil from whoosh.fields import SchemaClass, TEXT, NUMERIC from whoosh.filedb.filestore import FileStorage from whoosh.writing import AsyncWriter, BufferedWriter from whoosh import qparser from django.dispatch import receiver from django.db.models.signals import post_migrate from django.db.utils import IntegrityError from django.utils.encoding import force_text from django.db import transaction from weblate import appsettings from weblate.lang.models import Language from weblate.trans.data import data_dir STORAGE = FileStorage(data_dir('whoosh')) class TargetSchema(SchemaClass): ''' Fultext index schema for target strings. ''' pk = NUMERIC(stored=True, unique=True) target = TEXT() comment = TEXT() class SourceSchema(SchemaClass): ''' Fultext index schema for source and context strings. '''
def clean_indexes(): """ Cleans all indexes. """ shutil.rmtree(data_dir('whoosh')) STORAGE.create()
def _get_path(self): return os.path.join(data_dir('vcs'), self.slug)
def setup_index(): storage = FileStorage(data_dir('memory')) storage.create() return storage.create_index(TMSchema())