Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions burton/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import subprocess
import sys

import database
import parser
import translation
import vcs
from . import database
from . import parser
from . import translation
from . import vcs

from config import Config
from logginghandler import BurtonLoggingHandler
from stringmapping import StringMapping
from .config import Config
from .logginghandler import BurtonLoggingHandler
from .stringmapping import StringMapping

logger_name = "extensis.burton"
logging_handler = BurtonLoggingHandler()
Expand Down Expand Up @@ -77,7 +77,7 @@ def find_all_files(conf):
return return_files

def find_files_for_extension(conf, extension):
"""Finds all files recursively under thae root directory with the specified
"""Finds all files recursively under the root directory with the specified
extension"""

return_files = []
Expand Down Expand Up @@ -111,22 +111,36 @@ def extract_strings(conf, strings_to_ignore):
if regex is not None:
files.extend(find_files_for_extension(conf, regex))

strings.update(_extract_strings(parser_name, files, strings_to_ignore))
strings.update(_extract_strings(
parser_name,
files,
strings_to_ignore,
conf.get(Config.additional_function_names)
))

return strings

def _extract_strings(parser_name, files, strings_to_ignore):
def _extract_strings(
parser_name,
files,
strings_to_ignore,
additional_function_names
):
strings = set([])
if len(files) > 0:
cls = _class_from_string(parser_name)
parser = cls()
strings = parser.extract_strings_from_files(files, strings_to_ignore)
strings = parser.extract_strings_from_files(
files,
strings_to_ignore,
additional_function_names
)

return strings

def _get_extensions_by_parser(conf):
extensions_by_parser = { }
for key, value in conf.get(Config.parsers_by_extension).iteritems():
for key, value in conf.get(Config.parsers_by_extension).items():
extensions_by_parser[value] = extensions_by_parser.get(value, [])
extensions_by_parser[value].append(key)

Expand All @@ -150,19 +164,26 @@ def extract_mapping(conf, strings_to_ignore):
files.append(file)

reference_mapping.combine_with(
_extract_mapping(parser_name, files, strings_to_ignore)
_extract_mapping(
parser_name,
files,
strings_to_ignore,
conf.get(Config.additional_function_names)
)
)

return reference_mapping

def _extract_mapping(parser_name, files, strings_to_ignore):
def _extract_mapping(
parser_name, files, strings_to_ignore, additional_function_names):
reference_mapping = StringMapping()
if len(files) > 0:
cls = _class_from_string(parser_name)
parser = cls()
reference_mapping = parser.extract_string_mapping_from_files(
files,
strings_to_ignore
strings_to_ignore,
additional_function_names
)

return reference_mapping
Expand Down
127 changes: 63 additions & 64 deletions burton/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import codecs
import collections
import ConfigParser
import configparser
import json
import logging
import os
Expand Down Expand Up @@ -41,34 +41,35 @@ class Config(object):
"""

# Constants for config file variables
source_path = "source_path"
company_name = "company_name"
product_name = "product_name"
contact_email = "contact_email"
log_filename = "log_filename"
log_to_file = "log_to_file"
strings_to_ignore_file = "strings_to_ignore_file"
database_adaptor = "database_adaptor"
database_path = "database_path"
logging_level = "logging_level"
vcs_class = "vcs_class"
extensions_to_parse = "extensions_to_parse"
disallowed_paths = "disallowed_paths"
mapping_files = "mapping_files"
parsers_by_extension = "parsers_by_extension"
output_languages = "output_languages"
native_language = "native_language"
translation_files_class = "translation_files_class"
language_codes = "language_codes"
files_by_language = "files_by_language"
paths_to_localize = "paths_to_localize"
recursive_localization = "recursive_localization"
localization_output_dir = "localization_output_dir"
extensions_to_localize = "extensions_to_localize"
abort_if_no_translations = "abort_if_no_translations"
xlf_repo_path = "xlf_repo_path"
base_localization_paths = "base_localization_paths"
project_path = "project_path"
source_path = "source_path"
company_name = "company_name"
product_name = "product_name"
contact_email = "contact_email"
log_filename = "log_filename"
log_to_file = "log_to_file"
strings_to_ignore_file = "strings_to_ignore_file"
database_adaptor = "database_adaptor"
database_path = "database_path"
logging_level = "logging_level"
vcs_class = "vcs_class"
extensions_to_parse = "extensions_to_parse"
disallowed_paths = "disallowed_paths"
mapping_files = "mapping_files"
parsers_by_extension = "parsers_by_extension"
output_languages = "output_languages"
native_language = "native_language"
translation_files_class = "translation_files_class"
language_codes = "language_codes"
files_by_language = "files_by_language"
paths_to_localize = "paths_to_localize"
recursive_localization = "recursive_localization"
localization_output_dir = "localization_output_dir"
extensions_to_localize = "extensions_to_localize"
abort_if_no_translations = "abort_if_no_translations"
xlf_repo_path = "xlf_repo_path"
base_localization_paths = "base_localization_paths"
project_path = "project_path"
additional_function_names = "additional_function_names"

# Constants for command-line options
root_path = "root_path"
Expand All @@ -79,32 +80,33 @@ class Config(object):
commit_vcs = "commit_vcs"

_config_file_defaults = {
source_path : None,
company_name : "",
product_name : "",
contact_email : "",
strings_to_ignore_file : strings_to_ignore_file,
database_adaptor : None,
database_path : None,
logging_level : '"info"',
vcs_class : '"vcs.NoOp"',
extensions_to_parse : None,
disallowed_paths : None,
mapping_files : None,
parsers_by_extension : None,
output_languages : None,
native_language : None,
paths_to_localize : [],
recursive_localization : "false",
localization_output_dir : None,
extensions_to_localize : [],
files_by_language : {},
translation_files_class : "translation.XLF",
abort_if_no_translations : "false",
xlf_repo_path : None,
base_localization_paths : {},
project_path : "",
language_codes : {
source_path : None,
company_name : "",
product_name : "",
contact_email : "",
strings_to_ignore_file : strings_to_ignore_file,
database_adaptor : None,
database_path : None,
logging_level : '"info"',
vcs_class : '"vcs.NoOp"',
extensions_to_parse : None,
disallowed_paths : None,
mapping_files : None,
parsers_by_extension : None,
output_languages : None,
native_language : None,
paths_to_localize : [],
recursive_localization : "false",
localization_output_dir : None,
extensions_to_localize : [],
files_by_language : {},
translation_files_class : "translation.XLF",
abort_if_no_translations : "false",
xlf_repo_path : None,
base_localization_paths : {},
project_path : "",
additional_function_names : [],
language_codes : {
"English" : "en-US",
"French" : "fr-FR",
"German" : "de-DE",
Expand Down Expand Up @@ -224,7 +226,7 @@ def parse_command_line_options(self, script_name, options):
logger.error("usage: python " + script_name + " [path] [arguments]")
logger.error("This application takes the following arguments")
logger.error(
"\n\t".join(self._command_line_mapping.keys())
"\n\t".join(list(self._command_line_mapping.keys()))
)
return False

Expand All @@ -249,7 +251,7 @@ def parse_command_line_options(self, script_name, options):

if os.path.exists(full_path):
fp = self._open_for_reading(full_path)
parser = ConfigParser.SafeConfigParser(self._config_file_defaults)
parser = configparser.ConfigParser(defaults=self._config_file_defaults, allow_no_value=True)
parser.readfp(fp)
self._platform_queue.extend(parser.sections())

Expand Down Expand Up @@ -318,7 +320,7 @@ def readfp(self, fp, platform):
"""The readfp method reads configuration data from a file or file-like
object for a specific platform.
"""
parser = ConfigParser.SafeConfigParser(self._config_file_defaults)
parser = configparser.ConfigParser(defaults=self._config_file_defaults, allow_no_value=True)
parser.readfp(fp)

if not parser.has_section(platform):
Expand Down Expand Up @@ -394,16 +396,13 @@ def _apply_custom_method(self, key, value):
return method(value)

def _add_file_extension_regexes(self, values):
return map(
lambda(extension): re.compile(".*\." + extension + "$"),
values
)
return [re.compile(".*\." + extension + "$") for extension in values]

def _add_disallowed_path_regexes(self, values):
return map(lambda(directory): re.compile(directory), values)
return [re.compile(directory) for directory in values]

def _add_mapping_files_regexes(self, values):
return map(lambda(file): re.compile(file), values)
return [re.compile(file) for file in values]

def _open_for_reading(self, filename):
return open(filename, "r")
Expand Down
2 changes: 1 addition & 1 deletion burton/database/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from sqlite import SQLite
from .sqlite import SQLite
29 changes: 12 additions & 17 deletions burton/database/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ def _connect(self):
self.dbh = sqlite3.connect(self._temp_filename)

def _schema_file(self):
return resource_stream(
__name__,
"sqlite.schema"
)
return resource_stream(__name__, "sqlite.schema")

def _load_schema(self):
cursor = self.dbh.cursor()
fp = self._schema_file()
contents = fp.read()
if isinstance(contents, bytes):
contents = contents.decode()
cursor.executescript(
fp.read()
contents
)
fp.close()
cursor.close()

self.dbh.commit()

def _load_database(self):
Expand Down Expand Up @@ -135,9 +136,7 @@ def get_all_translation_keys(self):
""",
)

results = map(
lambda(key) : key[0].decode("unicode_escape"), cursor.fetchall()
)
results = [key[0].decode("unicode_escape") for key in cursor.fetchall()]
return results

def get_all_native_translations(self):
Expand All @@ -149,9 +148,7 @@ def get_all_native_translations(self):
""",
)

results = map(
lambda(key) : key[0].decode("unicode_escape"), cursor.fetchall()
)
results = [key[0].decode("unicode_escape") for key in cursor.fetchall()]
return results

def _insert_new_translation_keys(self, platform_no, mapping):
Expand Down Expand Up @@ -476,7 +473,7 @@ def get_platforms(self):
cursor = self.dbh.cursor()
cursor.execute("select name from platforms")

return_value = map(lambda(result) : result[0], cursor.fetchall())
return_value = [result[0] for result in cursor.fetchall()]
cursor.close()

return return_value
Expand All @@ -501,7 +498,7 @@ def get_string_mapping_for_platform(self, platform):
cursor.close()

return_value = { }
print results
print(results)
for translation_key in results:
return_value[translation_key.decode("unicode_escape")] = \
results[translation_key].decode("unicode_escape")
Expand All @@ -521,9 +518,7 @@ def get_native_translations_for_platform(self, platform):
( platform_no, )
)

results = map(
lambda(key) : key[0].decode("unicode_escape"), cursor.fetchall()
)
results = [key[0].decode("unicode_escape") for key in cursor.fetchall()]

cursor.close()

Expand Down
Loading