コード例 #1
0
def create_transform(project, module_name):

    transform_name = stringcase.pascalcase(module_name)
    module_name = module_name.lower()

    target = project.root_dir
    transform_directory = project.transforms_dir

    if os.path.exists(os.path.join(transform_directory,
                                   '%s.py' % module_name)):
        click.echo('Transform %r already exists... quitting' % module_name,
                   err=True)
        exit(-1)

    variables = parse_config(os.path.join(target, '.mrbob.ini'))['variables']

    variables.update({
        'transform.module': module_name,
        'transform.name': transform_name
    })

    configurator = Configurator('canari.resources.templates:create_transform',
                                target, {'non_interactive': True},
                                variables=variables)

    configurator.ask_questions()

    click.echo('Creating transform %r...' % module_name, err=True)
    configurator.render()

    click.echo('done!', err=True)
コード例 #2
0
    def __init__(self, path=None):
        if not path:
            path = os.getcwd()

        try:
            self._tree = self.project_tree(path)
            self._in_project = True
            self._configuration = parse_config(
                os.path.join(self.root_dir, '.mrbob.ini'))
            sys.path.insert(0, self.src_dir)
        except ValueError:
            self._tree = dict(root=path,
                              src=path,
                              pkg=path,
                              resources=path,
                              transforms=path)
            self._in_project = False
            self._configuration = {
                'variables': {
                    'created.year': date.today().year,
                    'author.name': getpass.getuser(),
                    'project.name': 'canari',
                    'canari.version': canari.__version__,
                    'author.email': '*****@*****.**',
                    'project.description': '',
                    'entity.base_name': 'Entity'
                }
            }
コード例 #3
0
    def project_tree(self, path):
        with PushDir(path):
            root = self._project_root()
            self._configuration = parse_config(os.path.join(
                root, '.mrbob.ini'))

            tree = dict(root=root,
                        src=os.path.join(root, 'src'),
                        pkg=os.path.join(root, 'src', self.name),
                        resources=os.path.join(root, 'src', self.name,
                                               'resources'),
                        transforms=os.path.join(root, 'src', self.name,
                                                'transforms'),
                        common=os.path.join(root, 'src', self.name,
                                            'transforms', 'common'))

            return tree
コード例 #4
0
def create_transform(args):

    opts = parse_args(args)
    project = CanariProject()

    transform_module = (opts.transform if not opts.transform.endswith('.py')
                        else opts.transform[:-3])
    transform_name = ''.join(
        [i[0].upper() + i[1:] for i in transform_module.split('_')])
    transform_module = transform_module.lower()

    if '.' in transform_module:
        print("Transform name (%r) cannot have a dot ('.')." % transform_name)
        exit(-1)
    elif not transform_module:
        print("You must specify a valid transform name.")
        exit(-1)

    target = project.root_dir
    transform_directory = project.transforms_dir

    if os.path.exists(
            os.path.join(transform_directory, '%s.py' % transform_module)):
        print('Transform %r already exists... quitting' % transform_module)
        exit(-1)

    variables = parse_config(os.path.join(target, '.mrbob.ini'))['variables']

    variables.update({
        'transform.module': transform_module,
        'transform.name': transform_name
    })

    configurator = Configurator(u'canari.resources.templates:create_transform',
                                target, {'non_interactive': True},
                                variables=variables)

    configurator.ask_questions()

    print('Creating transform %r...' % transform_module)
    configurator.render()

    print('done!')
コード例 #5
0
ファイル: create_transform.py プロジェクト: redcanari/canari3
def create_transform(args):

    opts = parse_args(args)
    project = CanariProject()

    transform_module = (opts.transform if not opts.transform.endswith('.py') else opts.transform[:-3])
    transform_name = ''.join([i[0].upper()+i[1:] for i in transform_module.split('_')])
    transform_module = transform_module.lower()

    if '.' in transform_module:
        print("Transform name (%r) cannot have a dot ('.')." % transform_name)
        exit(-1)
    elif not transform_module:
        print("You must specify a valid transform name.")
        exit(-1)

    target = project.root_dir
    transform_directory = project.transforms_dir

    if os.path.exists(os.path.join(transform_directory, '%s.py' % transform_module)):
        print('Transform %r already exists... quitting' % transform_module)
        exit(-1)

    variables = parse_config(os.path.join(target, '.mrbob.ini'))['variables']

    variables.update({'transform.module': transform_module, 'transform.name': transform_name})

    configurator = Configurator(
        'canari.resources.templates:create_transform',
        target,
        {'non_interactive': True},
        variables=variables
    )

    configurator.ask_questions()

    print('Creating transform %r...' % transform_module)
    configurator.render()

    print('done!')
コード例 #6
0
ファイル: project.py プロジェクト: redcanari/canari3
    def __init__(self, path=None):
        if not path:
            path = os.getcwd()

        try:
            self._tree = self.project_tree(path)
            self._in_project = True
            self._configuration = parse_config(os.path.join(self.root_dir, '.mrbob.ini'))
            sys.path.insert(0, self.src_dir)
        except ValueError:
            self._tree = dict(
                    root=path,
                    src=path,
                    pkg=path,
                    resources=path,
                    transforms=path
            )
            self._in_project = False
            self._configuration = {'variables': {'created.year': date.today().year, 'author.name': getpass.getuser(),
                                                 'project.name': 'canari', 'canari.version': canari.__version__,
                                                 'author.email': '*****@*****.**',
                                                 'project.description': '', 'entity.base_name': 'Entity'}}
コード例 #7
0
ファイル: test_parsing.py プロジェクト: tomster/mr.bob
def test_overwrite_value_with_dict():
    """ providing a dict for a key that already contains a
    string raises a ConfigurationError """
    from ..configurator import ConfigurationError
    with raises(ConfigurationError):
        parse_config(make_one('example4.ini'))
コード例 #8
0
ファイル: test_parsing.py プロジェクト: tomster/mr.bob
def test_overwrite_dict_with_value():
    """ providing a value for a key that already contains a
    dictionary raises a ConfigurationError """
    from ..configurator import ConfigurationError
    with raises(ConfigurationError):
        parse_config(make_one('example3.ini'))
コード例 #9
0
ファイル: test_parsing.py プロジェクト: tomster/mr.bob
 def setup():
     if 'config' in request.keywords:
         fs_filename = request.keywords['config'].args[0]
     else:
         fs_filename = 'example.ini'
     return parse_config(make_one(fs_filename))
コード例 #10
0
ファイル: test_parsing.py プロジェクト: tomster/mr.bob
def test_overwrite_value_with_dict():
    """ providing a dict for a key that already contains a
    string raises a ConfigurationError """
    from ..configurator import ConfigurationError
    with raises(ConfigurationError):
        parse_config(make_one('example4.ini'))
コード例 #11
0
ファイル: test_parsing.py プロジェクト: tomster/mr.bob
def test_overwrite_dict_with_value():
    """ providing a value for a key that already contains a
    dictionary raises a ConfigurationError """
    from ..configurator import ConfigurationError
    with raises(ConfigurationError):
        parse_config(make_one('example3.ini'))
コード例 #12
0
ファイル: test_parsing.py プロジェクト: tomster/mr.bob
 def setup():
     if 'config' in request.keywords:
         fs_filename = request.keywords['config'].args[0]
     else:
         fs_filename = 'example.ini'
     return parse_config(make_one(fs_filename))
コード例 #13
0
 def __init__(self, config_path):
     self.config = parse_config(config_path)