Ejemplo n.º 1
0
def pip_init():
    '''
    Initialize persistent data directories for pip installization
    '''

    sc_dir_ = sc_dir()
    templates = os.path.join(sc_dir_, 'templates')
    templates_dest = get_template_dir()
    configs = os.path.join(sc_dir_, 'conf')
    configs_dest = get_conf_dir()

    if not os.path.isdir(templates_dest):
        shutil.copytree(templates, templates_dest)
    if not os.path.isdir(configs_dest):
        shutil.copytree(configs, configs_dest)

    tmp_dir = get_tmp_dir()
    if not os.path.isdir(tmp_dir):
        os.mkdir(tmp_dir)
    
    db_dir = get_db_dir()
    if not os.path.isdir(db_dir):
        os.mkdir(db_dir)

    local_prods_dir = get_local_products_dir()
    if not os.path.isdir(local_prods_dir):
        os.mkdir(local_prods_dir)

    logs_dir = get_logging_dir()
    if not os.path.isdir(logs_dir):
        os.mkdir(logs_dir)
Ejemplo n.º 2
0
    def get_template_names():
        '''
        Get a list of the existing template names
        '''
        temp_folder = os.path.join(get_template_dir(), 'new_event')
        file_list = os.listdir(temp_folder)

        # get the names of the templates
        just_names = [f.split('.')[0] for f in file_list if f[-5:] == '.json']
        return just_names
Ejemplo n.º 3
0
 def save_configs(not_type, name, config):
     if isinstance(config, dict):
         conf_file = os.path.join(get_template_dir(), not_type,
                                  name + '.json')
         conf_str = open(conf_file, 'w')
         conf_str.write(json.dumps(config, indent=4))
         conf_str.close()
         return config
     else:
         return None
Ejemplo n.º 4
0
    def get_template_string(not_type, name=None):
        temp_name = 'default.html'
        if name is not None:
            temp_name = name + '.html'

        temp_file = os.path.join(get_template_dir(), not_type, temp_name)
        try:
            temp = open(temp_file, 'r')
            temp_str = temp.read()
            temp.close()
            return temp_str
        except Exception:
            return None
Ejemplo n.º 5
0
    def get_template(not_type, name=None, sub_dir=None):
        name = name or 'default.html'
        # force html file type
        if '.html' not in name:
            name += '.html'

        # default fallback template
        fallback = os.path.join('default', name) if sub_dir else 'default.html'

        # pdfs use a subdirectory
        name = os.path.join(sub_dir, name) if sub_dir else name

        html_file_name_template = os.path.join(get_template_dir(), not_type,
                                               '{}')

        custom_name = html_file_name_template.format(name)
        default_name = html_file_name_template.format(fallback)
        html_file_name = custom_name if os.path.isfile(
            custom_name) else default_name

        with open(html_file_name, 'r') as html_file:
            template = jinja_env.from_string(html_file.read())

        return template
Ejemplo n.º 6
0
    def get_configs(not_type, name=None, sub_dir=None):
        name = name or 'default.json'
        # force json file type
        if '.json' not in name:
            name += '.json'

        # default fallback configs
        fallback = os.path.join('default', name) if sub_dir else 'default.json'

        # pdfs use a subdirectory
        name = os.path.join(sub_dir, name) if sub_dir else name

        json_file_name_template = os.path.join(get_template_dir(), not_type,
                                               '{}')

        custom_name = json_file_name_template.format(name)
        default_name = json_file_name_template.format(fallback)
        conf_file_name = custom_name if os.path.isfile(
            custom_name) else default_name

        with open(conf_file_name, 'r') as conf_file:
            config = json.loads(conf_file.read())

        return config
Ejemplo n.º 7
0
 def save_template(not_type, name, template_str):
     temp_file = os.path.join(get_template_dir(), not_type, name + '.html')
     temp_file = open(temp_file, 'w')
     temp_file.write(template_str)
     temp_file.close()
     return temp_file