Exemplo n.º 1
0
    def create(component_name, coding_language='python'):
        data = {
            'name':
            _.snake_case(component_name),
            'class_name':
            _.start_case(_.camel_case(component_name)).replace(' ', ''),
            'cwd':
            os.getcwd()
        }
        coding_language = _.get(MAPPING, coding_language, coding_language)
        with open(REPO_DIR / f'{coding_language}.component',
                  'r') as template_file:
            code_template = template_file.read()
            code_template = code_template.replace('<%= ',
                                                  '${').replace(' %>', '}')
            render = Template(code_template).render

        file = render(**data)
        file_ending = ENDINGS[coding_language]
        file_path = f'./{data["name"]}.{file_ending}'

        with open(file_path, 'w') as component_file:
            component_file.write(file)

        os.chmod(file_path, 0o775)

        if Builder.color:
            print(Fore.GREEN + ' Component created.' + Style.RESET_ALL +
                  ' Try it by running ' + Fore.YELLOW + f'{file_path} help')
        else:
            print(f'Component created. Try it by running {file_path} help')
Exemplo n.º 2
0
    def get_py_name_from_php_name_stripped(php_name_stripped):
        # Prior to snake_casing the name, we have to handle some special cases:

        # Missing uppercase letter in sformat
        if php_name_stripped == "sformat":
            return "format"

        # bad CamelCase for IDS:
        # groupIDs would be converted to "group_i_ds"
        name = php_name_stripped.replace("IDs", "Ids")
        return pydash.snake_case(name)
Exemplo n.º 3
0
def load(reload=False):
    """Load configuration from file."""
    global diary_config, _config_loaded
    if not _config_loaded or reload:
        try:
            diary_config = os.environ.get("SPACE_DIARY_CONFIG", None)
            if diary_config is not None and os.path.exists(diary_config):
                import yaml  # NOQA
                import pydash  # NOQA
                with open(diary_config, 'r') as diary_config_file:
                    this = sys.modules[__name__]
                    yaml_config = yaml.load(diary_config_file.read())
                    print(yaml_config)
                    for key, val in yaml_config.items():
                        setattr(this, pydash.snake_case(key).upper(), val)
        except KeyError:
            diary_config = None
Exemplo n.º 4
0
 def from_dict(cls, obj, scale: int = None):
     parameters = obj.get('parameters', {})
     height = parameters.get('height', 200)
     unset(parameters, 'height')
     unset(parameters, 'width')
     component = TYPE_TO_COMPONENT[obj['type']](
         id_=obj['id'],
         height=height,
         width=scale,
         **{snake_case(k): v
            for k, v in parameters.items()})
     selections, container_ids, tags = obj.get('selections'), obj.get(
         'containerIds'), obj.get('tags')
     if selections:
         component.selections = [
             Selection.from_dict(selection) for selection in selections
         ]
     if container_ids:
         component.__container_ids = [
             containerId for containerId in container_ids
         ]
     if tags:
         component.tags = tags
     return component
Exemplo n.º 5
0
 def get_path(self, docname):
     path = '' if docname == 'index' else docname
     path = '/' + _.snake_case(path).replace('_', '-')
     return path
Exemplo n.º 6
0
def test_snake_case(case, expected):
    assert _.snake_case(case) == expected
Exemplo n.º 7
0
def main():
    lines = sys.stdin.read().split('\n')
    lines = [pydash.snake_case(x) for x in lines]
    print('\n'.join(lines))