Пример #1
0
def generator():
    """
    Code generator function, parse user arguments and load appropriate
    template module. Once loaded, run its data method depending on
    user requested input parameter, e.g. print_etags, print_tags or
    generate template code.
    """
    optmgr = SkeletonOptionParser()
    opts, args = optmgr.get_opt()
    test_env(os.path.join(opts.tdir, opts.tmpl), opts.tmpl)
    config = {'pname': opts.pname, 'tmpl': opts.tmpl, 'author': opts.author,
              'args': parse_args(args), 'debug': opts.debug,
              'ftype': opts.ftype, 'tmpl_dir': opts.tdir}
    if  opts.ketags:
        etags = opts.ketags.split(',')
        config.update({'tmpl_etags': etags})
    else:
        config.update({'tmpl_etags': []})
    obj = code_generator(config)
    if  opts.etags:
        obj.print_etags()
        sys.exit(0)
    elif opts.tags:
        obj.print_tags()
        sys.exit(0)
    elif opts.templates:
        for name in os.listdir(opts.tdir):
            print name
        sys.exit(0)
    obj.generate()
Пример #2
0
def generate(kwds):
    "Run generator code based on provided set of arguments"
    config = dict(kwds)
    tmpl   = kwds.get('tmpl')
    stand_alone_group = ['Record', 'Skeleton']
    config.update({'not_in_dir': stand_alone_group})
    if  tmpl in stand_alone_group:
        whereami, ldir = test_cms_environment(tmpl)
        dirs = ldir.split('/')
        config.update({'pkgname': kwds.get('pname')})
        config.update({'subsystem': 'Subsystem'})
        config.update({'pkgname': 'Package'})
        if  whereami:
            if  len(dirs) >= 3:
                config.update({'subsystem': dirs[1]})
                config.update({'pkgname': dirs[2]})
            elif len(dirs) >= 2:
                config.update({'subsystem': dirs[1]})
                config.update({'pkgname': dirs[1]})
    else:
        whereami, ldir = test_cms_environment(tmpl)
        dirs = ldir.split('/')
        if  not dirs or not whereami:
            print cms_error()
            sys.exit(1)
        config.update({'subsystem': dirs[1]})
        config.update({'pkgname': kwds.get('pname')})
        if  whereami in ['src', 'plugins']:
            config.update({'working_dir': whereami})
            config.update({'tmpl_files': '.cc'})
            config.update({'pkgname': dirs[2]})
        elif whereami == 'test':
            config.update({'working_dir': whereami})
            config.update({'tmpl_files':'.cc'})
            config.update({'pkgname': dirs[2]})
        elif whereami == 'subsystem':
            config.update({'tmpl_files': 'all'})
        else:
            print cms_error()
            sys.exit(1)
    obj = code_generator(config)
    obj.generate()
Пример #3
0
def generate(kwds):
    "Run generator code based on provided set of arguments"
    config = dict(kwds)
    tmpl = kwds.get('tmpl')
    stand_alone_group = ['Record', 'Skeleton']
    config.update({'not_in_dir': stand_alone_group})
    if tmpl in stand_alone_group:
        whereami, ldir = test_cms_environment(tmpl)
        dirs = ldir.split('/')
        config.update({'pkgname': kwds.get('pname')})
        config.update({'subsystem': 'Subsystem'})
        config.update({'pkgname': 'Package'})
        if whereami:
            if len(dirs) >= 3:
                config.update({'subsystem': dirs[1]})
                config.update({'pkgname': dirs[2]})
            elif len(dirs) >= 2:
                config.update({'subsystem': dirs[1]})
                config.update({'pkgname': dirs[1]})
    else:
        whereami, ldir = test_cms_environment(tmpl)
        dirs = ldir.split('/')
        if not dirs or not whereami:
            print(cms_error())
            sys.exit(1)
        config.update({'subsystem': dirs[1]})
        config.update({'pkgname': kwds.get('pname')})
        if whereami in ['src', 'plugins']:
            config.update({'working_dir': whereami})
            config.update({'tmpl_files': '.cc'})
            config.update({'pkgname': dirs[2]})
        elif whereami == 'test':
            config.update({'working_dir': whereami})
            config.update({'tmpl_files': '.cc'})
            config.update({'pkgname': dirs[2]})
        elif whereami == 'subsystem':
            config.update({'tmpl_files': 'all'})
        else:
            print(cms_error())
            sys.exit(1)
    obj = code_generator(config)
    obj.generate()