Commit 6030d5b9 authored by Michal Čihař's avatar Michal Čihař

Move directory creation to file format object

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 74332bc4
......@@ -670,6 +670,16 @@ class FileFormat(object):
'''
Adds new language file.
'''
# Create directory for a translation
dirname = os.path.dirname(fullname)
if not os.path.exists(dirname):
os.makedirs(dirname)
self.create_new_file(filename, code, base)
@classmethod
def create_new_file(cls, filename, code, base):
"""Handles creation of new translation file."""
if cls.new_translation is None:
raise ValueError('Not supported')
......@@ -794,10 +804,8 @@ class PoFormat(FileFormat):
return False
@classmethod
def add_language(cls, filename, code, base):
'''
Adds new language file.
'''
def create_new_file(cls, filename, code, base):
"""Handles creation of new translation file."""
with open(base, 'r') as handle:
data = handle.read()
# Assume input is UTF-8 if not specified
......@@ -962,10 +970,8 @@ class JSONFormat(FileFormat):
return True
@classmethod
def add_language(cls, filename, code, base):
'''
Adds new language file.
'''
def create_new_file(cls, filename, code, base):
"""Handles creation of new translation file."""
content = '{}\n'
if base:
with open(base, 'r') as handle:
......
......@@ -1437,11 +1437,6 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
)
fullname = os.path.join(self.get_path(), filename)
# Create directory for a translation
dirname = os.path.dirname(fullname)
if not os.path.exists(dirname):
os.makedirs(dirname)
self.file_format_cls.add_language(
fullname,
language.code,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment