Beispiel #1
0
 def do_GET(self):
     
     params = {"diffs": self.data}
     
     t = pyratemp.Template(filename=SCRIPT_DIR + "/index.html")
     result = t(**pyratemp.dictkeyclean(params))
     
     self.wfile.write(result)
Beispiel #2
0
    def do_GET(self):

        params = {"diffs": self.data}

        t = pyratemp.Template(filename=SCRIPT_DIR + "/index.html")
        result = t(**pyratemp.dictkeyclean(params))

        self.wfile.write(result)
Beispiel #3
0
def process_app(conf, app_dir):

    #get the name from the user
    print "please provide a name for your application (default: %s)" % conf[
        "name"]
    name = raw_input("> ")
    if len(name) == 0:
        name = conf['name']

    params = process_variables(conf)
    params['name'] = name

    #create destination folder
    dest_dir = current_dir + params['name'] + "/"
    if not os.path.exists(dest_dir):
        os.mkdir(dest_dir)

    #process files that should be created
    try:
        for file in conf["create_files"]:

            #see if the file has a name derived from a variable
            try:
                try:
                    name = file["name"] % params["name"]
                except TypeError:
                    name = file["name"]
            except KeyError:
                name = file["template"]

            file_name = file["template"]
            if os.path.exists(app_dir + file_name):
                #copy existing file
                t = pyratemp.Template(filename=app_dir + file_name)
                contents = t(**pyratemp.dictkeyclean(params)).encode("utf-8")
            else:
                #create blank file
                contents = ""

            #create directories in target if necessary
            target_dir = os.path.dirname(name)
            if target_dir and not os.path.exists(dest_dir + target_dir):
                os.makedirs(dest_dir + target_dir)

            f = open(dest_dir + name, "w")
            f.write(contents)
            f.close()

    except KeyError:
        pass
Beispiel #4
0
def process_app(conf, app_dir):

    #get the name from the user
    print "please provide a name for your application (default: %s)" % conf["name"]
    name = raw_input("> ")
    if len(name) == 0:
        name = conf['name']
    
    params = process_variables(conf)
    params['name'] = name

    #create destination folder
    dest_dir = current_dir + params['name'] + "/"
    if not os.path.exists(dest_dir):
        os.mkdir(dest_dir)

    #process files that should be created
    try:
        for file in conf["create_files"]:

            #see if the file has a name derived from a variable
            try:
                try:
                    name = file["name"] % params["name"]
                except TypeError:
                    name = file["name"]
            except KeyError:
                name = file["template"]

            file_name = file["template"]
            if os.path.exists(app_dir + file_name):
                #copy existing file
                t = pyratemp.Template(filename=app_dir + file_name)
                contents = t(**pyratemp.dictkeyclean(params)).encode("utf-8")
            else:
                #create blank file
                contents = ""

            #create directories in target if necessary
            target_dir = os.path.dirname(name)
            if target_dir and not os.path.exists(dest_dir + target_dir):
              os.makedirs(dest_dir + target_dir)

            f = open(dest_dir + name, "w")
            f.write(contents)
            f.close()

    except KeyError:
        pass
Beispiel #5
0
def load_data(datasetString):
    """
    Load data from data-files using either 'yaml' or 'simplejson'.
   
    Exits if data is invalid or neither 'yaml' nor 'simplejson' are found.

    :Parameters:
        - dataset: dataset with an extension, either .json or .yaml
    :Returns: read data (dict)
    """
    dataset = None

    try:
        import simplejson
        import pyratemp
        #
        # loading data from JSON. If this fails it will attempt to load it
        # as YAML.
        #
        dataset = pyratemp.dictkeyclean(simplejson.loads(datasetString))
    except ImportError:
        sys.stderr.write("ERROR: python-module 'simplejson' not found.\n")
        sys.exit(4)
    except ValueError:
        try:
            import yaml
            dataset = yaml.load(datasetString)
        except ImportError:
            sys.stderr.write("ERROR: python-module 'yaml' not found.\n")
            sys.exit(4)
        except ValueError:
            raise ValueError,"The given buffer is not valid JSON or YAML:\n%s" % datasetString
        except yaml.parser.ParserError,args:
            raise ValueError,"The given buffer is not valid JSON or YAML\n%s" % datasetString
        except yaml.scanner.ScannerError,args:
            raise ValueError,"The given buffer is not valid JSON or YAML\n%s" % datasetString
Beispiel #6
0
                print("ImportError/missing Python-module:",
                      str(err),
                      file=sys.stderr)
                sys.exit(1)
            except ValueError as err:
                print("Datafile error:", str(err), file=sys.stderr)
                sys.exit(20)

            localtime = time.localtime()
            data = {
                'mtime_CCYYMMDD': time.strftime("%Y-%m-%d", localtime),
                'date': time.strftime("%Y-%m-%d", localtime),
            }
            data.update(filedata)
            data.update(namevals)
            data = pyratemp.dictkeyclean(data)

            # render
            try:
                if output_xml:
                    result = t(**data).encode("ascii", "xmlcharrefreplace")
                else:
                    result = t(**data).encode("utf-8")
                os.write(sys.stdout.fileno(), result)
            except pyratemp.TemplateRenderError as err:
                print("file '%s':\n" % template_name, file=sys.stderr)
                print("  TemplateRenderError:", str(err), file=sys.stderr)
                sys.exit(30)

#-----------------------------------------
Beispiel #7
0
        sys.stderr.write(USAGE+"\n")
        sys.exit(2)
    for template_name in files:
        try:
            t = parse(template_name)
        except pyratemp.TemplateSyntaxError, err:
            sys.stderr.write("file '%s':\n" % template_name)
            sys.stderr.write("  TemplateSyntaxError: %s\n" % str(err))
            sys.exit(3)
        if render:
            filedata = load_data(datafiles)

            localtime = time.localtime()
            data = {
                    'mtime_CCYYMMDD':time.strftime("%Y-%m-%d",localtime),
                    'date'          :time.strftime("%Y-%m-%d",localtime),
                    }
            data.update(filedata)
            data.update(namevals)
            data = pyratemp.dictkeyclean(data)

            try:
                print t(**data).encode("utf-8"),
            except pyratemp.TemplateRenderError, err:
                sys.stderr.write("file '%s':\n" % template_name)
                sys.stderr.write("  TemplateRenderError: %s\n" % str(err))
                sys.exit(3)

#=========================================