コード例 #1
0
ファイル: imports.py プロジェクト: JanDeVisser/Grumble
 def run(self):
     # We set up the paths every time since the user could have switched
     # since last time.
     self._setuser()
     if self.user:
         inboxfiles = gripe.listdir(self.inbox)
         for f in inboxfiles:
             logger.debug("ScanInbox: Found file %s", f)
             gripe.rename(os.path.join(self.inbox, f), os.path.join(self.queue, f))
             self.addfile(os.path.join(gripe.root_dir(), self.queue, f))
コード例 #2
0
ファイル: smtp.py プロジェクト: JanDeVisser/pygrumble
 def _get_env(cls):
     if not hasattr(cls, "env"):
         loader = jinja2.ChoiceLoader([ \
             jinja2.FileSystemLoader("%s/%s" % (gripe.root_dir(), cls.template_dir)), \
             jinja2.PackageLoader("gripe", "template") \
         ])
         env = jinja2.Environment(loader=loader)
         if hasattr(cls, "get_env") and callable(cls.get_env):
             env = cls.get_env(env)
         cls.env = env
     return cls.env
コード例 #3
0
ファイル: maps.py プロジェクト: JanDeVisser/Grumble
 def drawMap(self):
     #=======================================================================
     # with open("sweattrails/qt/maps.html") as fd:
     #     html = fd.read()
     #     templ = string.Template(html)
     #     html = templ.substitute(
     #         bgcolor = "#343434", 
     #         fgcolor = "#FFFFFF", 
     #         mapskey = gripe.Config.app["config"].google_api_key)
     #=======================================================================
     self.setUrl(QUrl.fromLocalFile(os.path.join(gripe.root_dir(), "sweattrails/qt/maps.html")))
コード例 #4
0
ファイル: requesthandler.py プロジェクト: JanDeVisser/Grumble
 def _get_env(cls):
     if not hasattr(cls, "env"):
         loader = jinja2.ChoiceLoader([ \
             jinja2.FileSystemLoader("%s/%s" % (gripe.root_dir(), cls.template_dir)), \
             jinja2.PackageLoader("grit", "template") \
         ])
         env = jinja2.Environment(loader = loader, extensions = ['jinja2.ext.do'])
         if hasattr(cls, "get_env") and callable(cls.get_env):
             env = cls.get_env(env)
         cls.env = env
     return cls.env
コード例 #5
0
ファイル: imports.py プロジェクト: JanDeVisser/sweattrails
 def run(self):
     # We set up the paths every time since the user could have switched
     # since last time.
     self._setuser()
     if self.user:
         inbox_files = gripe.listdir(self.inbox)
         for f in inbox_files:
             if f.endswith(".fit"):
                 logger.debug("ScanInbox: Found file %s", f)
                 gripe.rename(os.path.join(self.inbox, f),
                              os.path.join(self.queue, f))
                 self.addfile(os.path.join(gripe.root_dir(), self.queue, f))
コード例 #6
0
    def test_0_ResetConfig(self):
        print("--- test_0: Cleaning up conf/* directory")
        d = os.path.join(gripe.root_dir(), "conf")
        
        unlink("unittest.json.backup")
        unlink("unittest.json")

        for f in os.listdir(d):
            (json, ext) = os.path.splitext(f)
            if ext == ".backup":
                unlink(json)
                print("mv %s %s" % (f, json))
                os.rename(os.path.join(d, f), os.path.join(d, json))
コード例 #7
0
ファイル: imports.py プロジェクト: JanDeVisser/sweattrails
 def process(self, antfile, data):
     with gripe.db.Tx.begin():
         path = os.path.join(gripe.root_dir(),
                             gripe.user_dir(self.user.uid()), "inbox",
                             self.get_filename(antfile))
         with open(path, "w") as fd:
             data.tofile(fd)
         f = self.get_filename(antfile)
         q = ImportedFITFile.query('"filename" =', f, parent=self.user)
         fitfile = q.get()
         if not fitfile:
             fitfile = ImportedFITFile(parent=self.user)
             fitfile.filename = f
         fitfile.status = False
         fitfile.put()
コード例 #8
0
ファイル: imports.py プロジェクト: JanDeVisser/Grumble
 def process(self, antfile, data):
     with gripe.db.Tx.begin():
         path = os.path.join(gripe.root_dir(), 
                             gripe.user_dir(self.user.uid()), 
                             "inbox",
                             self.get_filename(antfile))
         with open(path, "w") as fd:
             data.tofile(fd)
         f = self.get_filename(antfile)
         q = ImportedFITFile.query('"filename" =', f, parent = self.user)
         fitfile = q.get()
         if not fitfile:
             fitfile = ImportedFITFile(parent = self.user)
             fitfile.filename = f
         fitfile.status = False
         fitfile.put()
コード例 #9
0
 def _get_env(cls):
     if not hasattr(cls, "env"):
         fsloaders = []
         for app_dir in reversed(gripe.get_app_dirs()):
             dir = os.path.join(app_dir, cls.template_dir)
             fsloaders.append(jinja2.FileSystemLoader(dir))
         fsloaders.extend([
             jinja2.FileSystemLoader(
                 os.path.join(gripe.root_dir(), cls.template_dir)),
             jinja2.PackageLoader("grit", "template")
         ])
         loader = jinja2.ChoiceLoader(fsloaders)
         env = jinja2.Environment(loader=loader,
                                  extensions=['jinja2.ext.do'])
         if hasattr(cls, "get_env") and callable(cls.get_env):
             env = cls.get_env(env)
         cls.env = env
     return cls.env
コード例 #10
0
ファイル: statichandler.py プロジェクト: JanDeVisser/Grumble
 def get(self, *args, **kwargs):
     logger.info("StaticHandler.get(%s)", self.request.path)
     path = ''
     if "abspath" in kwargs:
         path = kwargs["abspath"]
     else:
         path = gripe.root_dir()
         if "relpath" in kwargs:
             path = os.path.join(path, kwargs["relpath"])
     path += self.request.path if not kwargs.get('alias') else kwargs.get("alias")
     if not os.path.exists(path):
         logger.info("Static file %s does not exist", path)
         self.request.response.status = "404 Not Found"
     else:
         if_none_match = self.request.if_none_match
         hashvalue = self.etags.get(path)
         if if_none_match and hashvalue and hashvalue in if_none_match:
             logger.debug("Client has up-to-date resource %s", path)
             self.response.status = "304 Not Modified"
         else:
             self.response.content_length = str(os.path.getsize(path))
             content_type = gripe.ContentType.for_path(path)
             self.response.content_type = content_type.content_type
             if content_type.is_text():
                 self.response.charset = "utf-8"
                 mode = "r"
             else:
                 mode = "rb"
             with open(path, mode) as fh:
                 buf = fh.read()
             if path not in self.etags:
                 hashvalue = hashlib.md5(buf).hexdigest()
                 self.etags[path] = hashvalue
                 if if_none_match and hashvalue in if_none_match:
                     logger.debug("Client has up-to-date resource %s. I had to hash it though", path)
                     self.response.status = "304 Not Modified"
                     return
             self.response.etag = hashvalue
             self.response.body = str(buf)
コード例 #11
0
 def dbdir(cls):
     return os.path.join(gripe.root_dir(), cls._dbdir)
コード例 #12
0
 def setup(cls, sqlite_conf):
     cls.config = sqlite_conf
     cls._dbdir = sqlite_conf.dbdir if "dbdir" in sqlite_conf else "db"
     if isinstance(sqlite_conf.wipe, bool) and sqlite_conf.wipe:
         shutil.rmtree(os.path.join(gripe.root_dir(), cls._dbdir))
     gripe.mkdir(cls._dbdir)
コード例 #13
0
ファイル: sqlite.py プロジェクト: JanDeVisser/Grumble
 def setup(cls, sqlite_conf):
     cls.config = sqlite_conf
     cls._dbdir = sqlite_conf.dbdir if "dbdir" in sqlite_conf else "db"
     if isinstance(sqlite_conf.wipe, bool) and sqlite_conf.wipe:
         shutil.rmtree(os.path.join(gripe.root_dir(), cls._dbdir))
     gripe.mkdir(cls._dbdir)
コード例 #14
0
ファイル: smtp.py プロジェクト: JanDeVisser/pygrumble
    def _get_template(self):
        tpl = self.template()
        if not tpl:
            tpl = self.get_template() \
                if hasattr(self, "get_template") and callable(self.get_template) \
                else None
        cname = self.__class__.__name__.lower()
        if not tpl:
            tpl = cname
        tpl = gripe.Config.app.get(cname, tpl)
        logger.info("TemplateMailMessage: using template %s", tpl)
        return self._get_env().get_template(tpl + ".txt")


if __name__ == '__main__':
    sendMail("*****@*****.**", "Test", """
Hi Jan,
    
This is a test.

Thanks,

jan
""", *["%s/image/Desert.jpg" % gripe.root_dir()])

    message = TemplateMailMessage("testmessage")
    message.recipients("*****@*****.**")
    message.subject("Test")
    message.send()
コード例 #15
0
ファイル: main.py プロジェクト: JanDeVisser/pygrumble
    print "Requested Test and got OK"

    d["froz"] = 43
    request = webapp2.Request.blank("/json/test")
    request.headers['Cookie'] = cookie
    request.method = "POST"
    request.content_type = "application/x-www-form-urlencoded"
    request.charset = "utf8"
    request.json = d
    response = request.get_response(app)
    assert response.status_int == 200, "Expected 200 OK, got %s" % response.status
    d = response.json
    k = d["key"]
    print "Updated Test and got OK"

    with open("%s/image/Desert.jpg" % gripe.root_dir(), "rb") as fh:
        img = fh.read()
    request = webapp2.Request.blank("/img/test/icon/%s" % k,
                                    POST={
                                        "contentType": "image/jpeg",
                                        "image": ("Desert.jpg", img)
                                    })
    request.headers['Cookie'] = cookie
    request.method = "POST"
    response = request.get_response(app)
    assert response.status_int == 200, "Expected 200 OK, got %s" % response.status
    print "Updated Test with image and got OK"

    try:
        os.remove("image/Desert_1.jpg")
    except:
コード例 #16
0
ファイル: pyxslt.py プロジェクト: JanDeVisser/pygrumble
    @processor.for_end_of("^/$")
    def doc_end(context):
        print(" - - -  E N D - - -")

    @processor.for_text_of("^/.+/@[a-zA-Z]+$")
    def attr_value(context, text):
        print(context.indent + "  " + context.xmlp_current + "=" + text)

    @processor.for_text_of("test/@quux")
    def quux(context, text):
        print(context.indent + "  The quux value is " + text)

    @processor.for_text_of("test/frob")
    def frob(context, text):
        print(context.indent + "The frob value is --" + text + "--")

    fname = os.path.join(gripe.root_dir(), "..", "test", "test.xml")

    print("===== process(filename)")
    processor.process(fname)

    print("===== process(stream)")
    with open(fname) as f:
        processor.process(f)

    print("===== process_string()")
    with open(fname) as f:
        xmltext = f.read()
        processor.process_string(xmltext)
コード例 #17
0
    def get(self, *args, **kwargs):
        request = self.request
        route = request.route
        logger.info("StaticHandler.get(%s)", request.path)
        reqpath = route.grit_params["alias"] if 'alias' in route.grit_params else request.path

        path = None
        full_path = None
        if "abspath" in route.grit_params:
            if os.path.isabs(reqpath):
                reqpath = reqpath[1:]
            full_path = os.path.join(kwargs["abspath"], reqpath)
        elif "relpath" in route.grit_params:
            prefix = os.path.commonprefix([route.grit_params["path"], reqpath])
            relative = os.path.relpath(reqpath, prefix)
            if os.path.isabs(relative):
                relative = relative[1:]
            relpath = route.grit_params["relpath"]
            if os.path.isabs(relpath):
                relpath = relpath[1:]
            path = os.path.join(relpath, relative)
        else:
            path = reqpath

        if not full_path:
            logger.debug("Finding full path for path %s", path)
            if os.path.isabs(path):
                path = path[1:]
            for dir in reversed(gripe.get_app_dirs()):
                full_path = os.path.join(dir, path)
                if os.path.exists(full_path):
                    break
                else:
                    full_path = None
            if not full_path:
                full_path = os.path.join(gripe.root_dir(), path)
                if not os.path.exists(full_path):
                    full_path = None
            logger.debug("Going ahead with full path %s", full_path)
        else:
            if not os.path.exists(full_path):
                full_path = None

        if not full_path:
            logger.info("Static file %s does not exist", path)
            self.request.response.status = "404 Not Found"
        else:
            logger.debug("Serving static file %s", full_path)
            if_none_match = self.request.if_none_match
            hashvalue = self.etags.get(full_path)
            if if_none_match and hashvalue and hashvalue in if_none_match:
                logger.debug("Client has up-to-date resource %s: %s %s", full_path, if_none_match, hashvalue)
                self.response.status = "304 Not Modified"
            else:
                self.response.content_length = str(os.path.getsize(full_path))
                content_type = gripe.ContentType.for_path(full_path)
                self.response.content_type = content_type.content_type
                if content_type.is_text():
                    self.response.charset = "utf-8"
                    mode = "r"
                else:
                    mode = "rb"
                with open(full_path, mode) as fh:
                    buf = fh.read()
                if full_path not in self.etags:
                    hashvalue = hashlib.md5(buf).hexdigest()
                    self.etags[full_path] = hashvalue
                    if if_none_match and hashvalue in if_none_match:
                        logger.debug("Client has up-to-date resource %s. I had to hash it though. %s %s", full_path, if_none_match, hashvalue)
                        self.response.status = "304 Not Modified"
                        return
                self.response.etag = hashvalue
                self.response.body = str(buf)
コード例 #18
0
ファイル: sqlite.py プロジェクト: JanDeVisser/Grumble
 def dbdir(cls):
     return os.path.join(gripe.root_dir(), cls._dbdir)