コード例 #1
0
def load_recipe_ingredients_list(recipe_directory, input_recipe, recipe_list):
  class RecipeObject():
    def __init__ (self, recipe_list):
      self.recipe_list = recipe_list

  lineorder = ""
  recipe_file = open(os.path.join(recipe_directory,input_recipe), 'r')
  for line in recipe_file:
    recipe_object = parse_recipe(line,type)
    got_descriptor = recipe_object.descriptor
    if got_descriptor == "TEXTQTY":
      if recipe_object.value == "":
        recipe_quantity = "0"
      else:
        recipe_quantity = recipe_object.value
    elif got_descriptor == "MEASURE":
      if len(recipe_object.value) < 1:
        recipe_measure = "ea"
      else:
        recipe_measure = recipe_object.value
    elif got_descriptor == "NAME":
      recipe_name = recipe_object.value
    elif got_descriptor == "PREPNOTES":
      recipe_name += " " + recipe_object.value
    elif got_descriptor == "LINEORDER":
      lineorder = recipe_object.value
      recipe_list.append([lineorder, recipe_quantity, recipe_measure, recipe_name.rstrip()])
  recipe_file.close()
  return RecipeObject(recipe_list)
コード例 #2
0
def load_recipe_header_list(recipe_directory, input_recipe, recipe_list):
  class RecipeObject():
    def __init__ (self, recipe_list):
      self.recipe_list = recipe_list

  header_list = ["TITLE","CATEGORIES","YIELDTEXT","SUBHEAD","VARIATIONS","INSTRUCTIONS"]
  values_list = []
  got_recipe_list = load_recipe_list(recipe_directory, input_recipe, recipe_list)
  for desc in range(len(header_list)):
    i = index_containing_substring(got_recipe_list.recipe_list, "<" + header_list[desc])
    j = index_containing_substring(got_recipe_list.recipe_list, "</" + header_list[desc])
    recipe_value = ""
    if j == -1:
      values_list.append("")
      continue
  
    for a in range(i,j+1):
      line = got_recipe_list.recipe_list[a]
      recipe_object = parse_recipe(line,type)    
      got_descriptor = recipe_object.descriptor
      if got_descriptor == header_list[desc]:
        recipe_value = recipe_object.value
      elif got_descriptor == "":
        recipe_value += recipe_object.value  
    values_list.append(recipe_value)
  recipe_list.append(values_list)
  return RecipeObject(recipe_list)
 def assertTranslates(self, input_recipe, output_recipe):
   recipe_object = parse_recipe(input_recipe,type)
   got_descriptor, got_value = recipe_object.descriptor, recipe_object.value
   new_recipe = ""
   if got_descriptor == "TITLE":
     new_recipe = "      Title: " + got_value 
   if got_descriptor == "CATEGORIES":
     new_recipe = " Categories: " + got_value 
   if got_descriptor == "YIELDTEXT":
     new_recipe = "      Yield: " + got_value 
   if got_descriptor == "INSTRUCTIONS":
     new_recipe = got_value 
   self.assertEqual(new_recipe, output_recipe)
コード例 #4
0
ファイル: buildall.py プロジェクト: mbits-os/tpm
import os, sys, recipe
from subprocess import check_call

pkgs = {}
for root, dir, files in os.walk('recipes'):
	for filename in files:
		pkgs[os.path.join(root, filename)] = []

remove = []
for conf in pkgs:
	try: result = recipe.parse_recipe(conf)
	except recipe.SyntaxError as se:
		sys.stderr.write(se.pretty())
		sys.stderr.write('\n')
		remove.append(conf)
		continue
	except:
		remove.append(conf)
		continue
	pkgs[conf] = [os.path.join('packages', pkg.name) for pkg in result.packages]

for conf in remove:
	del pkgs[conf]

def mtime(path):
	if not os.path.exists(path): return 0
	return os.stat(path).st_mtime

confs = []
for conf in sorted(pkgs):
	needs_update = False
コード例 #5
0
 def assertValue(self, input_string, descriptor, value, type):
     recipe_object = parse_recipe(input_string, type)
     got_descriptor = recipe_object.descriptor
     self.assertEqual(got_descriptor, descriptor)
     got_value = recipe_object.value
     self.assertEqual(got_value, value)
コード例 #6
0
ファイル: build.py プロジェクト: mbits-os/tpm
import os, sys, subprocess, glob, wget, archive, hashlib, recipe

try:
	result = recipe.parse_recipe(sys.argv[1])
except SyntaxError as se:
	sys.stderr.write(se.pretty())
	sys.stderr.write('\n')
	exit(1)

def mkdir(path):
	if os.path.exists(path): return
	sys.stdout.write('+ mkdir -p {}\n'.format(path))
	os.makedirs(path)

def rm(path):
	if not os.path.exists(path): return
	if os.path.isdir(path):
		sys.stdout.write('+ rm -r {}\n'.format(path))
		os.removedirs(path)
		return

	sys.stdout.write('+ rm {}\n'.format(path))
	os.remove(path)

def cd(path):
	sys.stdout.write('+ cd {}\n'.format(path))
	os.chdir(path)

def bar_none(current, total, width=80): return ''

sys.stdout.write('=' * 80 + '\n')