Skip to content

Commit

Permalink
Windows fix for popen and unicode_literals + import_project CLI
Browse files Browse the repository at this point in the history
second fix for glob-related windows bugs

fix for realpath() and windows backslashes
  • Loading branch information
Anonymous Coward committed Apr 11, 2016
1 parent 49e1d83 commit 85795df
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion weblate/trans/management/commands/import_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_matching_files(self, repo):
Returns relative path of matched files.
'''
matches = glob(os.path.join(repo, self.filemask))
return [f.replace(repo, '').strip('/') for f in matches]
return [f.replace(repo, '').replace('\\', '/').strip('/') for f in matches]

def get_matching_subprojects(self, repo):
'''
Expand Down
4 changes: 2 additions & 2 deletions weblate/trans/models/subproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,10 @@ def update_branch(self, request=None, method=None):

def get_mask_matches(self):
"""Returns files matching current mask."""
prefix = os.path.join(self.get_path(), '')
prefix = os.path.join(self.get_path(), '').replace('\\', '/')
matches = set()
for filename in glob(os.path.join(self.get_path(), self.filemask)):
path = filename.replace(prefix, '')
path = filename.replace('\\', '/').replace(prefix, '')
code = self.get_lang_code(path)
if re.match(self.language_regex, code):
matches.add(path)
Expand Down
14 changes: 7 additions & 7 deletions weblate/trans/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def run_hook(component, translation, script, *args):
target = component.linked_subproject
else:
target = component
environment['WL_VCS'] = target.vcs
environment['WL_REPO'] = target.repo
environment['WL_PATH'] = target.get_path()
environment['WL_FILEMASK'] = component.filemask
environment['WL_TEMPLATE'] = component.template
environment['WL_FILE_FORMAT'] = component.file_format
environment[str('WL_VCS')] = str(target.vcs)
environment[str('WL_REPO')] = str(target.repo)
environment[str('WL_PATH')] = str(target.get_path())
environment[str('WL_FILEMASK')] = str(component.filemask)
environment[str('WL_TEMPLATE')] = str(component.template)
environment[str('WL_FILE_FORMAT')] = str(component.file_format)
if translation:
environment['WL_LANGUAGE'] = translation.language_code
environment[str('WL_LANGUAGE')] = str(translation.language_code)
try:
subprocess.check_call(
command,
Expand Down
6 changes: 3 additions & 3 deletions weblate/trans/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ def get_clean_env(extra=None):
Returns cleaned up environment for subprocess execution.
"""
environ = {
'LANG': 'en_US.UTF-8',
'HOME': data_dir('home'),
str('LANG'): str('en_US.UTF-8'),
str('HOME'): str(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]
environ[str(var)] = str(os.environ[var])
return environ


Expand Down
6 changes: 3 additions & 3 deletions weblate/trans/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def resolve_symlinks(self, path):
Resolves any symlinks in the path.
"""
# Resolve symlinks first
real_path = os.path.realpath(os.path.join(self.path, path))
repository_path = os.path.realpath(self.path)
real_path = os.path.realpath(os.path.join(self.path, path)).replace('\\', '/')
repository_path = os.path.realpath(self.path).replace('\\', '/')

if not real_path.startswith(repository_path):
raise ValueError('Too many symlinks or link outside tree')
Expand All @@ -149,7 +149,7 @@ def _popen(cls, args, cwd=None):
process = subprocess.Popen(
args,
cwd=cwd,
env=get_clean_env({'GIT_SSH': ssh_file(SSH_WRAPPER)}),
env=get_clean_env({str('GIT_SSH'): str(ssh_file(SSH_WRAPPER))}),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
Expand Down

0 comments on commit 85795df

Please # to comment.