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()))
class Starter(object): def __init__(self): self.manager = RecipesManager() def check(self): if not self.manager.list(): logger.info(" :: I think it's your first time with sushi") logger.info(" :: Can I suggest you simple basic recipe ?") return True return False def run(self): url = 'https://github.com/Socketubs/Sushi/raw/master/recipes/basic.tar.gz' logger.info(' :: Searching') r = requests.get(url, prefetch=False) try: r.raise_for_status() except Exception as err: raise StarterException( "Sorry I can't find this old recipe in my cookbook. Try later. (%s)" % err) src = os.path.join(conf.get('paths', 'sushi_recipes'), 'basic.tar.gz') dst = conf.get('paths', 'sushi_recipes') with open(src, 'w') as f: for buf in r.iter_content(1024): if buf: f.write(buf) logger.info(' :: Teaching') # Open tarfile tar = tarfile.open(src, 'r:gz') if tarfile.is_tarfile(src): tar.extractall(dst) else: raise Exception('Archive invalid (not a gzipped tarfile)') # Remove archive os.remove(src) logger.info(' :: Done')
class Starter(object): def __init__(self): self.manager = RecipesManager() def check(self): if not self.manager.list(): logger.info(" :: I think it's your first time with sushi") logger.info(" :: Can I suggest you simple basic recipe ?") return True return False def run(self): url = 'https://github.com/Socketubs/Sushi/raw/master/recipes/basic.tar.gz' logger.info(' :: Searching') r = requests.get(url, prefetch=False) try: r.raise_for_status() except Exception as err: raise StarterException("Sorry I can't find this old recipe in my cookbook. Try later. (%s)" % err) src = os.path.join(conf.get('paths', 'sushi_recipes'), 'basic.tar.gz') dst = conf.get('paths', 'sushi_recipes') with open(src, 'w') as f: for buf in r.iter_content(1024): if buf: f.write(buf) logger.info(' :: Teaching') # Open tarfile tar = tarfile.open(src, 'r:gz') if tarfile.is_tarfile(src): tar.extractall(dst) else: raise Exception('Archive invalid (not a gzipped tarfile)') # Remove archive os.remove(src) logger.info(' :: Done')
def start(self): ################### # craft # ################### if self.args.get('craft', False): logger.info('==> Craft your project') path = self.args.get('<path>') recipe = self.args.get('--recipe', False) if not recipe: recipe = conf.get('settings', 'recipe', 'default') logger.info(' => Recipe: %s' % recipe) try: unbundle(recipe, path) except Exception as err: logger.info('Error: %s (%s)' % (err, recipe)) sys.exit(1) logger.info('==> Call helpers') run_helpers(recipe, path) logger.info('==> Done') ################### # learn # ################### elif self.args.get('learn', False): recipes = self.args.get('<name>') manager = RecipesManager() try: for recipe in recipes: logger.info('==> Learn %s' % recipe) manager.add(recipe) except RecipeAlreadyLearn as err: logger.error('Error: %s' % err) sys.exit(1) logger.info('==> Done') ################### # forget # ################### elif self.args.get('forget', False): recipes = self.args.get('<name>') manager = RecipesManager() try: for recipe in recipes: logger.info('==> Forget %s' % recipe) manager.delete(recipe) logger.info('==> Done') except Exception as err: logger.error('Error: %s' % err) sys.exit(1) ################### # list # ################### elif self.args.get('list', False): manager = RecipesManager() recipes = manager.list() if not recipes: logger.info('==> No recipe learned') sys.exit(1) logger.info('==> Recipes learned') for recipe in recipes: logger.info(recipe) sys.exit(0) ################### # all # ################### elif self.args.get('all', False): manager = RecipesManager() recipes = manager.list_available() if not recipes: logger.info('==> No recipe available') sys.exit(1) logger.info('==> Recipes available') for recipe in recipes: logger.info(recipe) sys.exit(0) ################### # upgrade # ################### elif self.args.get('upgrade', False): cb = Cookbook() logger.info('==> Update cookbooks') cookbooks = cb.upgrade(ignore_errors=True) ################### # cookbook # ################### elif self.args.get('cookbook', False): cb = Cookbook() cookbooks = cb.list() if not cookbooks: logger.info('==> No cookbooks registered') sys.exit(1) logger.info('==> Cookbooks') for cookbook in cookbooks: logger.info(cookbook) sys.exit(0) ################### # cookbook-add # ################### elif self.args.get('cookbook-add', False): repo_name = self.args.get('<name>')[0] logger.info('==> Add %s cookbook' % repo_name) cb = Cookbook() try: cb.add(repo_name) logger.info('==> Done') except CookbookException as err: logger.info('Error: %s' % err) sys.exit(1) sys.exit(0) ################### # cookbook-del # ################### elif self.args.get('cookbook-del', False): repo_name = self.args.get('<name>')[0] logger.info('==> Delete %s cookbook' % repo_name) cb = Cookbook() if confirm(): try: cb.remove(repo_name) logger.info('==> Done') except CookbookException as err: logger.info('Error: %s' % err) sys.exit(1) else: print('Abort.') sys.exit(1) sys.exit(0) sys.exit(100)
def __init__(self): self.manager = RecipesManager()
def start(self): ################### # craft # ################### if self.args.get('craft', False): logger.info('==> Craft your project') path = self.args.get('<path>') recipe = self.args.get('--recipe', False) if not recipe: recipe = conf.get('settings', 'recipe', 'default') logger.info(' => Recipe: %s' % recipe) try: unbundle(recipe, path) except Exception as err: logger.info('!! %s (%s)' % (err.message, recipe)) sys.exit(1) logger.info('==> Call helpers') run_helpers(recipe, path) logger.info('==> Done') ################### # learn # ################### elif self.args.get('learn', False): recipes = self.args.get('<name>') manager = RecipesManager() try: for recipe in recipes: logger.info('==> Learn %s' % recipe) manager.add(recipe) except RecipeAlreadyLearn as err: logger.error('!! %s' % err.message) sys.exit(1) except RecipeUnvailable as err: logger.error('!! %s' % err.message) sys.exit(1) logger.info('==> Done') ################### # forget # ################### elif self.args.get('forget', False): recipes = self.args.get('<name>') manager = RecipesManager() try: for recipe in recipes: logger.info('==> Forget %s' % recipe) manager.delete(recipe) logger.info('==> Done') except Exception as err: logger.error('!! %s' % err.message) sys.exit(1) ################### # list # ################### elif self.args.get('list', False): manager = RecipesManager() recipes = manager.list() if not recipes: logger.info('==> No recipe learned') sys.exit(1) logger.info('==> Recipes learned') for recipe in recipes: logger.info(recipe) sys.exit(0) ################### # all # ################### elif self.args.get('all', False): manager = RecipesManager() recipes = manager.list_available() if not recipes: logger.info('==> No recipe available') sys.exit(1) logger.info('==> Recipes available') for recipe in recipes: logger.info(recipe) sys.exit(0) ################### # upgrade # ################### elif self.args.get('upgrade', False): cb = Cookbook() logger.info('==> Update cookbooks') cookbooks = cb.upgrade(ignore_errors=True) ################### # cookbook # ################### elif self.args.get('cookbook', False): cb = Cookbook() cookbooks = cb.list() if not cookbooks: logger.info('==> No cookbooks registered') sys.exit(1) logger.info('==> Cookbooks') for cookbook in cookbooks: logger.info(cookbook) sys.exit(0) ################### # cookbook-add # ################### elif self.args.get('cookbook-add', False): repo_name = self.args.get('<name>')[0] logger.info('==> Add %s cookbook' % repo_name) cb = Cookbook() try: cb.add(repo_name) logger.info('==> Done') except CookbookException as err: logger.info('!! %s' % err.message) sys.exit(1) sys.exit(0) ################### # cookbook-del # ################### elif self.args.get('cookbook-del', False): repo_name = self.args.get('<name>')[0] logger.info('==> Delete %s cookbook' % repo_name) cb = Cookbook() if confirm(): try: cb.remove(repo_name) logger.info('==> Done') except CookbookException as err: logger.info('!! %s' % err.message) sys.exit(1) else: print('Abort.') sys.exit(1) sys.exit(0) sys.exit(100)