Fix mixed path separators on Windows
parent
802d2e31e7
commit
023d53b986
|
@ -3,6 +3,19 @@ import io
|
|||
import os
|
||||
import polib
|
||||
|
||||
"""
|
||||
Conversion functions to avoid mixed \ and / path separators under Windows
|
||||
"""
|
||||
def convert_input_path(slash_path):
|
||||
if not slash_path:
|
||||
return None
|
||||
return slash_path.replace('/', os.sep)
|
||||
|
||||
def convert_output_path(system_path):
|
||||
if not system_path:
|
||||
return None
|
||||
return system_path.replace(os.sep, '/')
|
||||
|
||||
"""
|
||||
Works like shell's "mkdir -p" and also behaves nicely if given None argument
|
||||
"""
|
||||
|
@ -55,7 +68,7 @@ class TemplateFile:
|
|||
"""
|
||||
def insert_entry(self, text, occurrence, type_comment):
|
||||
entry = self.current_catalog.find(text)
|
||||
relative_file_name = os.path.relpath(occurrence.file_name, self.dir_name)
|
||||
relative_file_name = convert_output_path(os.path.relpath(occurrence.file_name, self.dir_name))
|
||||
occurrence = (relative_file_name, occurrence.line_number)
|
||||
if entry:
|
||||
entry.comment = self._merge_comment(entry.comment, type_comment)
|
||||
|
|
|
@ -4,7 +4,7 @@ import argparse
|
|||
import os
|
||||
import sys
|
||||
|
||||
from common import create_template_and_language_files, nice_mkdir
|
||||
from common import create_template_and_language_files, nice_mkdir, convert_input_path, convert_output_path
|
||||
from translate_help import create_help_translation_jobs
|
||||
from translate_level import create_level_translation_jobs
|
||||
from translate_chaptertitles import create_chaptertitles_translation_jobs
|
||||
|
@ -33,7 +33,15 @@ def parse_args():
|
|||
parser.add_argument('--signal_file',
|
||||
help = 'Signal file to indicate successful operation')
|
||||
|
||||
return parser.parse_args()
|
||||
args = parser.parse_args()
|
||||
|
||||
args.input_dir = convert_input_path(args.input_dir)
|
||||
args.po_dir = convert_input_path(args.po_dir)
|
||||
args.output_dir = convert_input_path(args.output_dir)
|
||||
args.output_subdir = convert_input_path(args.output_subdir)
|
||||
args.signal_file = convert_input_path(args.signal_file)
|
||||
|
||||
return args
|
||||
|
||||
def preprocess_args(args):
|
||||
if not os.path.isdir(args.input_dir):
|
||||
|
@ -73,8 +81,8 @@ def print_files(translation_jobs):
|
|||
input_files = []
|
||||
output_files = []
|
||||
for translation_job in translation_jobs:
|
||||
input_files.append(translation_job.get_input_file_name())
|
||||
output_files.append(translation_job.get_output_file_name())
|
||||
input_files.append(convert_output_path(translation_job.get_input_file_name()))
|
||||
output_files.append(convert_output_path(translation_job.get_output_file_name()))
|
||||
|
||||
sys.stdout.write(';'.join(input_files))
|
||||
sys.stdout.write('\n')
|
||||
|
|
Loading…
Reference in New Issue