<commit_before>import os
from configparser import ConfigParser

from database.restconfiguration import RestConfiguration


class ConfigSave(object):
    def __init__(self, file_name, default_configuration):
        self.default_configuration = default_configuration
        self.file_name = file_name

    def load(self):
        config_object = RestConfiguration()
        if not os.path.exists(self.file_name):
            section_map = {}
        else:
            config_file = open(self.file_name, 'r')
            root_section = "GIFT-Cloud Browser"
            config = ConfigParser.ConfigParser()
            section_map = config.read(root_section)
            config_file.close()
        config_object.server_name = ConfigSave.get_optional(section_map, 'server_name', self.default_configuration)
        config_object.base_url = ConfigSave.get_optional(section_map, 'base_url', self.default_configuration)
        config_object.user_name = ConfigSave.get_optional(section_map, 'user_name', self.default_configuration)
        config_object.password = ConfigSave.get_optional(section_map, 'password', self.default_configuration)
        return config_object

    def save(self, configuration):
        config_file = open(self.file_name, 'w')

        root_section = "GIFT-Cloud Browser"
        config = ConfigParser()
        config.add_section(root_section)
        config.set(root_section, 'server_name', configuration.server_name)
        config.set(root_section, 'url', configuration.base_url)
        config.set(root_section, 'user_name', configuration.user_name)
        config.set(root_section, 'password', configuration.password)
        config.write(config_file)

        config_file.close()

    @staticmethod
    def get_optional(map, property_name, default_map):
        if property_name in map:
            return map[property_name]
        else:
            return default_map[property_name]<commit_msg>Add load of properties from Uploader ini file<commit_after>import os
from configparser import ConfigParser

from browser.PropertyParser import PropertyParser
from browser.browserconfiguration import BrowserConfiguration
from database.restconfiguration import RestConfiguration


class ConfigSave(object):
    def __init__(self, file_name, default_configuration):
        self.default_configuration = default_configuration
        self.file_name = file_name

    def load(self):
        config_object = RestConfiguration()
        if not os.path.exists(self.file_name):
            section_map = ConfigSave.load_from_properties()
        else:
            root_section = "GIFT-Cloud Browser"
            config = ConfigParser()
            config.read(self.file_name)
            section_map = {}
            settings = config.options(root_section)
            for setting in settings:
                section_map[setting] = config.get(root_section, setting)
        config_object.server_name = ConfigSave.get_optional(section_map, 'server_name', self.default_configuration)
        config_object.base_url = ConfigSave.get_optional(section_map, 'base_url', self.default_configuration)
        config_object.user_name = ConfigSave.get_optional(section_map, 'user_name', self.default_configuration)
        config_object.password = ConfigSave.get_optional(section_map, 'password', self.default_configuration)
        return config_object

    def save(self, configuration):
        config_file = open(self.file_name, 'w')

        root_section = "GIFT-Cloud Browser"
        config = ConfigParser()
        config.add_section(root_section)
        config.set(root_section, 'server_name', configuration.server_name)
        config.set(root_section, 'url', configuration.base_url)
        config.set(root_section, 'user_name', configuration.user_name)
        config.set(root_section, 'password', configuration.password)
        config.write(config_file)

        config_file.close()

    @staticmethod
    def get_optional(map, property_name, default_map):
        if property_name in map:
            return map[property_name]
        else:
            return default_map[property_name]

    @staticmethod
    def load_from_properties():
        base = BrowserConfiguration.get_user_directory()
        properties_file = os.path.join(base, "GiftCloudUploader.properties")
        section_map = {}
        if os.path.exists(properties_file):
            properties = PropertyParser(properties_file)
            section_map['url'] = properties.properties['giftcloud_serverurl']
            section_map['user_name'] = properties.properties['giftcloud_lastusername']
        return section_map

{'fraction_non_alphanumeric': 0.0834597875569044, 'fraction_numerical': 0.0, 'mean_word_length': 3.3041044776119404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5792018', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1213, 'n_words': 235}