Esempio n. 1
0
	def write_file(self, file_name):
		loader = CachingFileLoader("html")
		template = loader.load_template("layout.html")
		html = template.merge({"vm": self }, loader=loader)
		f = open(file_name, "w")
		f.write(html)
		f.close()
Esempio n. 2
0
 def write_file(self, file_name):
     loader = CachingFileLoader("html")
     template = loader.load_template("layout.html")
     html = template.merge({"vm": self}, loader=loader)
     f = open(file_name, "w")
     f.write(html)
     f.close()
def sendMail(frm, to, subject, templateName, context):
    loader = CachingFileLoader("templates")

    templateNameHTML = templateName + ".vm"
    templateHTML = loader.load_template(templateNameHTML)
    bodyHTML = templateHTML.merge(context, loader=loader)

    templateNamePlain = templateName + "_plain.vm"
    templatePlain = loader.load_template(templateNamePlain)
    bodyPlain = templatePlain.merge(context, loader=loader)

    #    resp.headers['Content-Type']='text/html'
    msg = mail.EmailMessage(sender=frm, to=to, subject=subject)
    msg.html = bodyHTML
    msg.body = bodyPlain

    msg.send()
Esempio n. 4
0
def generate(fileName, templateName, context):
  print('Generating '+str(fileName))
  loader=CachingFileLoader("../templates")
  template=loader.load_template(templateName)
  result=template.merge(context, loader=loader)
  f=open(fileName, 'w')
  f.write(result)
  f.close()
Esempio n. 5
0
def sendMail(frm, to, subject, templateName, context):
    loader = CachingFileLoader("templates")

    templateNameHTML = templateName + ".vm"
    templateHTML = loader.load_template(templateNameHTML)
    bodyHTML = templateHTML.merge(context, loader=loader)

    templateNamePlain = templateName + "_plain.vm"
    templatePlain = loader.load_template(templateNamePlain)
    bodyPlain = templatePlain.merge(context, loader=loader)

    #    resp.headers['Content-Type']='text/html'
    msg = mail.EmailMessage(sender=frm, to=to, subject=subject)
    msg.html = bodyHTML
    msg.body = bodyPlain

    msg.send()
Esempio n. 6
0
  def execute(self, method, user, req, resp, args):
    loader = CachingFileLoader("templates")
    templateName=self.__class__.__name__.lower()
    if templateName[-4:]=='page':
      templateName=templateName[:-4]
    templateName=templateName+".vm"
    template = loader.load_template(templateName)
    context={}
    context['user']=user
    self.processContext(method.upper(), user, req, resp, args, context)
    body=template.merge(context, loader=loader)
#    resp.headers['Content-Type']='text/html'
    resp.out.write(body)
    for i in ranges:
        cmd=deepcopy(value)
        for k in cmd.keys():
            cmd[k]*=i
        function={"name":str(i)+key,"value":cmd[cmd.keys()[0]],"function":cmd.keys()[0]}
        VARS["FUNCTIONS"].append(function)
        
for key,value in tests_multi.items():
    cmd=deepcopy(value)
    function={"name":key,"value":cmd[cmd.keys()[0]],"function":cmd.keys()[0]}
    VARS["FUNCTIONS"].append(function)
    
for key,value in tests_single.items():
    cmd=deepcopy(value)
    function={"name":key,"value":cmd[cmd.keys()[0]],"function":cmd.keys()[0]}
    VARS["FUNCTIONS"].append(function)


loader = CachingFileLoader(".")
template = loader.load_template(os.path.dirname(__file__) + "/templates/recurrenceTemplate.java")


directory=sys.argv[1]+'/src/'+path+'/';
# print("Finish generating Test for "+className)
if not os.path.exists(directory):
    os.makedirs(directory)
f = open(directory+filename, 'w')
f.write(template.merge(VARS,loader=loader))
f.close()

#!/usr/bin/python2
import sys
import os
from airspeed import CachingFileLoader

if len(sys.argv) != 3:
    print(sys.argv[0]+" <taskList.json> <pathToTestDir>")
    sys.exit()

path="de/azapps/mirakel/model/task"
filename="TaskDeserializerTest.java"

vars = {}
vars["JSON_LIST"]=[]
with open(sys.argv[1]) as f:
    for s in f:
        vars["JSON_LIST"].append(s.strip())


loader = CachingFileLoader(".")
template = loader.load_template(os.path.dirname(__file__) + "/model/jsonTemplate.java")


directory=sys.argv[2]+'/src/'+path+'/';
# print("Finish generating Test for "+className)
if not os.path.exists(directory):
    os.makedirs(directory)
f = open(directory+filename, 'w')
f.write(template.merge(vars,loader=loader))
f.close()
Esempio n. 9
0
#!/usr/bin/python2
import sys
import os
from airspeed import CachingFileLoader

if len(sys.argv) != 3:
    print(sys.argv[0] + " <taskList.json> <pathToTestDir>")
    sys.exit()

path = "de/azapps/mirakel/model/task"
filename = "TaskDeserializerTest.java"

vars = {}
vars["JSON_LIST"] = []
with open(sys.argv[1]) as f:
    for s in f:
        vars["JSON_LIST"].append(s.strip())

loader = CachingFileLoader(".")
template = loader.load_template(
    os.path.dirname(__file__) + "/model/jsonTemplate.java")

directory = sys.argv[2] + '/src/' + path + '/'
# print("Finish generating Test for "+className)
if not os.path.exists(directory):
    os.makedirs(directory)
f = open(directory + filename, 'w')
f.write(template.merge(vars, loader=loader))
f.close()
Esempio n. 10
0
#!/usr/bin/python
import sys
import os
import yaml
try:
    import airspeed
except ImportError:
    import sys, os
    sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
    import airspeed
from airspeed import CachingFileLoader
loader = CachingFileLoader(sys.argv[1])
template = loader.load_template(sys.argv[2])
template_out_f = open(sys.argv[3], 'w')
template_list_f = open(sys.argv[4], 'r')
template_list = yaml.safe_load(template_list_f)
template_out_f.write(template.merge(template_list, loader=loader))
Esempio n. 11
0
File: compile.py Progetto: dj74/Dust
for modelName in models:
  print(modelName)
  modelBasename=modelName.split('.')[0]
  modelBases.append(modelBasename)
  modelFilename=modelDir+'/'+modelName
  outputDir=packageDir+'/'+modelBasename
  if not os.path.exists(outputDir):
    os.mkdir(outputDir)
  outputName=outputDir+'/'+modelBasename+'.'+lang
  testOutputName=outputDir+'/'+modelBasename+'_test.'+lang

  model=parse(modelFilename)
  context=convertModel(modelBasename, model, lang)

  print("Generating %s" % (modelBasename+'.'+lang))
  template = loader.load_template(templateName)
  body=template.merge(context, loader=loader)
  save(body, outputName)
  print("Formatting %s" % (modelBasename+'.'+lang))
  formatCode(outputName, lang)

  print("Generating test %s" % (modelBasename+'_test.'+lang))
  template = loader.load_template(testTemplateName)
  body=template.merge(context, loader=loader)
  save(body, testOutputName)
  print("Formatting test %s" % (modelBasename+'_test.'+lang))
  formatCode(testOutputName, lang)

if lang=='go':
  context={'models': modelBases, 'packageName': packageName, 'packageBase': packageBase}
  print("Generating models.go")
            params = getParams(groups[1])
            ptype = params[0]
            getterFunction = ""
            if ptype["type"] == "boolean":
                getterFunction = "is" + name + "()"
            else:
                getterFunction = "get" + name + "()"
            vars["SETTERS"].append({
                "name": name,
                "params":params,
                "type": ptype["type"].replace("@Nullable","").replace("@NonNull",""),
                "setterFunction":randomFunction("set"+name,params),
                "randomFunction": getRandom(params[0]),
                "getterFunction": getterFunction
            })

        importM = importRegex.search(line)
        if importM != None:
            groups = importM.groups()
            vars["IMPORTS"].append(groups[0])

create_line  = None
loader = CachingFileLoader(".")
template = loader.load_template(os.path.dirname(__file__) + "/templates/modelBase.java")

if not os.path.exists(directory):
    os.makedirs(directory)
f = open(directory+"/"+className+'Test.java', 'w')
f.write(template.merge(vars,loader=loader))
f.close()
Esempio n. 13
0
    def convert_to_pds4(self):
        # Make all ^ objects in PDS3 file compliant with PRS4 PTR_
        for key in self.labels.keys():
            if '^' in key:
                pointer_fname = self.file_name  # default to the file name of the label
                associated_object = self.get_object(key)
                # print('*************')
                # print(" '^' in {}".format(key))
                if self.labels[key][0] == '(' and self.labels[key][
                        -1] == ')':  # test for leading and trailing parenthesis
                    no_parenthesis = self.labels[key][
                        1:-1]  # strip out first and last characters
                    self.labels[key] = no_parenthesis
                # Check for additional leading description words in definition (e.g. LABEL_TABLE)
                if '_' in key:
                    temp_key = key.split('_')
                    ptr_key = '^' + temp_key[-1]
                else:
                    ptr_key = key

                self.labels[key] = self.labels[key].replace(
                    ' ', '')  # take out all blanks in the string
                self.labels[key] = self.labels[key].replace(
                    '"', '')  # take out any double quotes
                self.labels[key] = self.labels[key].replace(
                    "'", '')  # take out any sing quotes
                # print("label key: {}".format(self.labels[key]))

                if ptr_key in self.data_pointers:

                    if '<BYTES>' in self.labels[
                            key]:  # handle (^IMAGE = 600 <BYTES>)
                        # print(self.labels[key])
                        if (len(self.labels[key].split(','))
                            ) == 1:  # case we need to alter
                            new_string = self.file_name + ',' + self.labels[key]
                            self.labels[key] = new_string
                        else:  # case ("INDEX.TAB",<20BYTES>) no changes needed
                            pointer_fname = self.labels[key].split(',')[0]
                    else:
                        if (
                                len(self.labels[key].split(','))
                        ) == 1:  # case ^IMAGE = 12 or ^INDEX_TABLE = "INDEX.TAB"
                            if self.represents_int(self.labels[key]):
                                bytes = self.record_bytes * (
                                    int(self.labels[key]) - 1)
                                new_string = self.file_name + ',' + str(
                                    bytes) + '<BYTES>'
                                self.labels[key] = new_string
                            else:
                                new_string = self.labels[key] + ',0<BYTES>'
                                pointer_fname = self.labels[key]
                                self.labels[key] = new_string
                        elif (len(self.labels[key].split(','))
                              ) == 2:  # case ^SERIES = ("C100306.DAT", 2)
                            # print('6')
                            vals = self.labels[key].split(',')
                            bytes = self.record_bytes * (int(vals[1]) - 1)
                            new_string = vals[0] + ',' + str(bytes) + '<BYTES>'
                            pointer_fname = vals[0]
                            self.labels[key] = new_string
                            # print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
                            #print(new_string, self.labels[key])
                            # print(4)
                        else:
                            # print('7')
                            print('some kind of error')

                    offset = self.get_offset(self.labels[key])

                new_key = key.replace(
                    '^', 'PTR_')  # change pds3 '^' to pds4 'PTR_' in the key
                self.object_type = new_key.split('_')[-1] + '_0'
                if 'HEADER' in self.object_type:
                    continue
                # print('object type: {}'.format(self.object_type))
                self.labels[new_key] = self.labels.pop(key)

                # add to file_object dictionary.
                # Must do it this way because dict[key][nth field in <value>]  syntax is not recognized in Velocity
                # TODO Note: perhaps a better way of doing this is to set up one dictionary as:
                # TODO       ptr_object_offset_dict = {"<fname>": [object, object_offset]
                self.add_to_file_dict(pointer_fname, associated_object,
                                      self.ptr_object_dict)
                self.add_to_file_dict(pointer_fname, int(offset),
                                      self.ptr_offset_dict)

        # pprint.pprint(label1.keys())
        # pprint.pprint(self.labels)
        # pprint.pprint(self.ptr_object_dict)
        # pprint.pprint(self.ptr_offset_dict)

        # TODO "strip all leading and trailing whitespace in dict. = done
        # TODO "Strip double quotes from entries in dict.  - done

        loader = CachingFileLoader(resource_path("./templates"))
        template = loader.load_template("inspectTemplate.vm")
        map = {
            'label': self.labels,
            'str': str,
            'generate': self.generate,
            'ptr_object_map': self.ptr_object_dict,
            'ptr_offset_map': self.ptr_offset_dict,
            'object_placeholder': self.object_type
        }

        out = template.merge(map, loader=loader)
        # print(type(out))
        # pprint.pprint(out)

        pds4_xml_file = self.dir + '/' + self.file_name_no_ext + '.xml'

        with open(pds4_xml_file, 'w') as f:
            f.write(out.encode('utf8'))

        return pds4_xml_file
Esempio n. 14
0
            vars["SETTERS"].append({
                "name":
                name,
                "params":
                params,
                "type":
                ptype["type"].replace("@Nullable", "").replace("@NonNull", ""),
                "setterFunction":
                randomFunction("set" + name, params),
                "randomFunction":
                getRandom(params[0]),
                "getterFunction":
                getterFunction
            })

        importM = importRegex.search(line)
        if importM != None:
            groups = importM.groups()
            vars["IMPORTS"].append(groups[0])

create_line = None
loader = CachingFileLoader(".")
template = loader.load_template(
    os.path.dirname(__file__) + "/templates/modelBase.java")

if not os.path.exists(directory):
    os.makedirs(directory)
f = open(directory + "/" + className + 'Test.java', 'w')
f.write(template.merge(vars, loader=loader))
f.close()
Esempio n. 15
0
for key, value in tests_multi.items():
    cmd = deepcopy(value)
    function = {
        "name": key,
        "value": cmd[cmd.keys()[0]],
        "function": cmd.keys()[0]
    }
    VARS["FUNCTIONS"].append(function)

for key, value in tests_single.items():
    cmd = deepcopy(value)
    function = {
        "name": key,
        "value": cmd[cmd.keys()[0]],
        "function": cmd.keys()[0]
    }
    VARS["FUNCTIONS"].append(function)

loader = CachingFileLoader(".")
template = loader.load_template(
    os.path.dirname(__file__) + "/templates/recurrenceTemplate.java")

directory = sys.argv[1] + '/src/' + path + '/'
# print("Finish generating Test for "+className)
if not os.path.exists(directory):
    os.makedirs(directory)
f = open(directory + filename, 'w')
f.write(template.merge(VARS, loader=loader))
f.close()
Esempio n. 16
0
for modelName in models:
    print(modelName)
    modelBasename = modelName.split('.')[0]
    modelBases.append(modelBasename)
    modelFilename = modelDir + '/' + modelName
    outputDir = packageDir + '/' + modelBasename
    if not os.path.exists(outputDir):
        os.mkdir(outputDir)
    outputName = outputDir + '/' + modelBasename + '.' + lang
    testOutputName = outputDir + '/' + modelBasename + '_test.' + lang

    model = parse(modelFilename)
    context = convertModel(modelBasename, model, lang)

    print("Generating %s" % (modelBasename + '.' + lang))
    template = loader.load_template(templateName)
    body = template.merge(context, loader=loader)
    save(body, outputName)
    print("Formatting %s" % (modelBasename + '.' + lang))
    formatCode(outputName, lang)

    print("Generating test %s" % (modelBasename + '_test.' + lang))
    template = loader.load_template(testTemplateName)
    body = template.merge(context, loader=loader)
    save(body, testOutputName)
    print("Formatting test %s" % (modelBasename + '_test.' + lang))
    formatCode(testOutputName, lang)

if lang == 'go':
    context = {
        'models': modelBases,