예제 #1
0
def _copy_project(config, title, project_root):
    """`init` helper to push the project skeleton through templates 
    and copy over."""
    
    secret = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
    start = os.path.join(kraftwerk.templates_root, 'project')
    
    for dirpath, dirnames, filenames in os.walk(start):
        # Copy template skeleton
        for name in dirnames + filenames:
            
            path = os.path.join(dirpath, name)
            rel = relpath(path, start)
            
            project_rel = rel
            if "project" in rel:
                project_rel = rel.replace("project", title)

            dest_path = os.path.join(project_root, project_rel)

            if not os.path.exists(dest_path):
                if os.path.isdir(path):
                    os.makedirs(dest_path)
                else:
                    with codecs.open(dest_path, 'w', encoding='utf-8') as fp:
                        tpl = config.templates.get_template(os.path.join('project', rel))
                        fp.write(tpl.render({'project_title': title, 'secret': secret}))
예제 #2
0
파일: setup.py 프로젝트: igudym/kraftwerk
def find_package_data():
    files = []
    src_root = join(dirname(__file__), 'kraftwerk')
    static_root = join(src_root, 'templates')
    for dirpath, subdirs, filenames in os.walk(static_root):
        for filename in filenames:
            if not filename.startswith('.') or filename.startswith('_'):
                abs_path = join(dirpath, filename)
                files.append(relpath(abs_path, start=src_root))
    return files
예제 #3
0
파일: setup.py 프로젝트: igudym/kraftwerk
def find_package_data():
    files = []
    src_root = join(dirname(__file__), 'kraftwerk')
    static_root = join(src_root, 'templates')
    for dirpath, subdirs, filenames in os.walk(static_root):
        for filename in filenames:
            if not filename.startswith('.') or filename.startswith('_'):
                abs_path = join(dirpath, filename)
                files.append(relpath(abs_path, start=src_root))
    return files
예제 #4
0
파일: config.py 프로젝트: igudym/kraftwerk
 def for_file(cls, filename):
     """Get the configuration from a given YAML file."""
     
     if not os.path.exists(filename):
         relative = relpath(os.path.dirname(filename), start=os.getcwd())
         basename = os.path.basename(filename)
         if relative == '.':
             raise ConfigNotFound("%s was not found in the current directory" % basename)
         raise ConfigNotFound("%s was not found in %s" % (basename, relative))
     
     with open(filename) as fp:
         config = yaml.load(fp) or {}
     
     return cls(filename, config)