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): ...@@ -670,6 +670,16 @@ class FileFormat(object):
''' '''
Adds new language file. 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: if cls.new_translation is None:
raise ValueError('Not supported') raise ValueError('Not supported')
...@@ -794,10 +804,8 @@ class PoFormat(FileFormat): ...@@ -794,10 +804,8 @@ class PoFormat(FileFormat):
return False return False
@classmethod @classmethod
def add_language(cls, filename, code, base): def create_new_file(cls, filename, code, base):
''' """Handles creation of new translation file."""
Adds new language file.
'''
with open(base, 'r') as handle: with open(base, 'r') as handle:
data = handle.read() data = handle.read()
# Assume input is UTF-8 if not specified # Assume input is UTF-8 if not specified
...@@ -962,10 +970,8 @@ class JSONFormat(FileFormat): ...@@ -962,10 +970,8 @@ class JSONFormat(FileFormat):
return True return True
@classmethod @classmethod
def add_language(cls, filename, code, base): def create_new_file(cls, filename, code, base):
''' """Handles creation of new translation file."""
Adds new language file.
'''
content = '{}\n' content = '{}\n'
if base: if base:
with open(base, 'r') as handle: with open(base, 'r') as handle:
......
...@@ -1437,11 +1437,6 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1437,11 +1437,6 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
) )
fullname = os.path.join(self.get_path(), filename) 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( self.file_format_cls.add_language(
fullname, fullname,
language.code, 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