def ignore(folder, names): _res = [] for n in names: if not os.path.isdir(os.path.join(folder, n)): if conf.has_option('settings', 'ignore'): if n in conf.get('settings', 'ignore').split(): _res.append(n) return _res
def unbundle(recipe, dst): manager = RecipesManager() recipe_dir = manager.get(recipe) if manager.name_handler(recipe) not in manager.list_available(): raise UnbundlerException("Don't know this recipe.") env = get_env(dst) if os.path.exists(dst): raise UnbundlerException('Destination (%s) already exist' % dst) ################## # Copy every dir # ################## def ignore(folder, names): _res = [] for n in names: if not os.path.isdir(os.path.join(folder, n)): if conf.has_option('settings', 'ignore'): if n in conf.get('settings', 'ignore').split(): _res.append(n) return _res shutil.copytree(recipe_dir, dst, ignore=ignore) ############################################ # Copy every file and render it on the fly # ############################################ for path, dirs, files in os.walk(recipe_dir): for f in files: if conf.has_option('settings', 'ignore'): if f in conf.get('settings', 'ignore').split(): continue fdst = os.path.join(path.replace(recipe_dir, dst), f) try: with codecs.open(fdst, mode='w', encoding='utf-8') as r: r.write(render(os.path.join(path, f), **env)) except Exception as err: logger.info(' | Failed for %s (%s)' % (f, err)) ###################################### # Rename every __app__ to {{ name }} # ###################################### for r, s, f in os.walk(dst): # Folders if "__app__" in s: os.rename(os.path.join(r, "__app__"), os.path.join(r, env['app'].lower())) for r, s, f in os.walk(dst): # Files if "__app__" in f: os.rename(os.path.join(r, "__app__"), os.path.join(r, env['app'].lower()))
def get_env(name): now = datetime.datetime.now() extras = [u'firstname', u'lastname', u'email'] d = { u'username': unicode(getpass.getuser()), u'app': unicode(name), u'year': unicode(now.year), u'day': unicode(now.day), u'month': unicode(now.month), u'hour': unicode(now.hour), u'minute': unicode(now.minute), u'second': unicode(now.second), u'date': unicode(now.strftime("%Y-%m-%d %H:%M")) } for extra in extras: if conf.has_option('settings', extra): d[extra] = conf.get('settings', extra).decode('utf-8') else: d[extra] = '## Set %s' % extra return d