Ejemplo n.º 1
0
def create_transform(args):

    opts = parse_args(args)

    initf = os.path.join(opts.transform_dir, '__init__.py')
    transform = opts.transform if not opts.transform.endswith('.py') else opts.transform[:-3]

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

    directory = opts.transform_dir
    transformf = os.path.join(directory, opts.transform if opts.transform.endswith('.py') else '%s.py' % opts.transform)

    if not os.path.exists(initf):
        print ('Directory %s does not appear to be a python package directory... quitting!' % repr(opts.transform_dir))
        exit(-1)
    if os.path.exists(transformf):
        print ('Transform %s already exists... quitting' % repr(transformf))
        exit(-1)

    values = init_pkg()

    write_template(
        transformf,
        read_template('newtransform', values)
    )

    print ('updating %s' % initf)
    init = file(initf).read()

    with file(initf, mode='wb') as w:
        w.write(
            re.sub(
                r'__all__\s*\=\s*\[',
                '__all__ = [\n    %s,' % repr(transform),
                init
            )
        )

    print ('done!')
Ejemplo n.º 2
0
def run(args):

    opts = parse_args(args)

    initf = path.join(opts.transform_dir, '__init__.py')
    transform = opts.transform if not opts.transform.endswith('.py') else opts.transform[:-3]

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

    directory = opts.transform_dir
    transformf = path.join(directory, opts.transform if opts.transform.endswith('.py') else '%s.py' % opts.transform )

    if not path.exists(initf):
        print ('Directory %s does not appear to be a python package directory... quitting!' % repr(opts.transform_dir))
        exit(-1)
    if path.exists(transformf):
        print ('Transform %s already exists... quitting' % repr(transformf))
        exit(-1)

    values = init_pkg()

    write_template(
        transformf,
        read_template('newtransform', values)
    )

    print ('updating %s' % initf)
    init = file(initf).read()

    with file(initf, mode='wb') as w:
        w.write(
            sub(
                r'__all__\s*\=\s*\[',
                '__all__ = [\n    %s,' % repr(transform),
                init
            )
        )

    print ('done!')
Ejemplo n.º 3
0
def run(args):

    opts = parse_args(args)

    initf = path.join(opts.transform_dir, '__init__.py')
    transform = opts.transform
    directory = opts.transform_dir
    transformf = path.join(directory, transform if transform.endswith('.py') else '%s.py' % transform )

    if not path.exists(initf):
        print ('Directory %s does not appear to be a python package directory... quitting!' % repr(opts.transform_dir))
        exit(-1)
    if path.exists(transformf):
        print ('Transform %s already exists... quitting' % repr(transformf))
        exit(-1)

    values = init_pkg()

    write_template(
        transformf,
        read_template('newtransform', values)
    )

    print ('updating %s' % initf)
    init = file(initf).read()

    with file(initf, mode='wb') as w:
        w.write(
            sub(
                r'__all__\s*\=\s*\[',
                '__all__ = [\n    %s,' % repr(transform),
                init
            )
        )

    print ('done!')