Exemplo n.º 1
0
    def getMemberList(self):
        """Return list of (direct) collection member names (UTF-8 byte strings).

        See DAVResource.getMemberList()
        """
        members = []
        conn = self.provider._initConnection()
        try:
            tableName, primKey = self.provider._splitPath(self.path)
            if tableName is None:
                retlist = self.provider._listTables(conn)
                for name in retlist:
                    members.append(
                        MySQLBrowserResource(self.provider,
                                             util.joinUri(self.path, name),
                                             True, self.environ))
            elif primKey is None:
                pri_key = self.provider._findPrimaryKey(conn, tableName)
                if pri_key is not None:
                    retlist = self.provider._listFields(
                        conn, tableName, pri_key)
                    for name in retlist:
                        members.append(
                            MySQLBrowserResource(self.provider,
                                                 util.joinUri(self.path, name),
                                                 False, self.environ))
                members.insert(
                    0,
                    MySQLBrowserResource(
                        self.provider,
                        util.joinUri(self.path, "_ENTIRE_CONTENTS"), False,
                        self.environ))
        finally:
            conn.close()
        return members
Exemplo n.º 2
0
 def getMemberList(self):
     """Return list of (direct) collection member names (UTF-8 byte strings).
     
     See DAVResource.getMemberList()
     """
     members = []
     conn = self.provider._initConnection()
     try:
         tableName, primKey = self.provider._splitPath(self.path)
         if tableName is None:
             retlist = self.provider._listTables(conn)         
             for name in retlist:
                 members.append(MySQLBrowserResource(self.provider, 
                                                     util.joinUri(self.path, name), 
                                                     True, 
                                                     self.environ))
         elif primKey is None:
             pri_key = self.provider._findPrimaryKey(conn, tableName)
             if pri_key is not None:
                 retlist = self.provider._listFields(conn, tableName, pri_key)      
                 for name in retlist:
                     members.append(MySQLBrowserResource(self.provider, 
                                                         util.joinUri(self.path, name), 
                                                         False, 
                                                         self.environ))
             members.insert(0, MySQLBrowserResource(self.provider, 
                                                    util.joinUri(self.path, "_ENTIRE_CONTENTS"), 
                                                    False, 
                                                    self.environ))
     finally:      
         conn.close()
     return members
Exemplo n.º 3
0
 def getMember(self, name):
     if name in self._artifactNames:
         return VirtualArtifact(joinUri(self.path, name), self.environ, self.data)
     for filePath in self.data["resPathList"]:
         fname = os.path.basename(filePath)
         if fname == name:
             return VirtualResFile(joinUri(self.path, name), self.environ, self.data, filePath)
     return None
Exemplo n.º 4
0
 def getMember(self, name):
     if name in self._artifactNames:
         return VirtualArtifact(joinUri(self.path, name), self.environ, self.data)
     for filePath in self.data["resPathList"]:
         fname = os.path.basename(filePath)
         if fname == name:
             return VirtualResFile(joinUri(self.path, name), self.environ, self.data, filePath)
     return None
Exemplo n.º 5
0
 def getMember(self, name):
     if self.name == "by_key":
         data = _getResByKey(name)
         if data:
             return VirtualResource(joinUri(self.path, name), self.environ, data)
         else:
             return None
     return CategoryCollection(joinUri(self.path, name), self.environ, self.name)
Exemplo n.º 6
0
 def getMember(self, name):
     # Handle visible categories and also /by_key/...
     if name == "by_alphabet":
         return AlphabetCollection(joinUri(self.path, name), self.environ)
     elif name == "by_genre":
         return GenreCollection(joinUri(self.path, name), self.environ)
     _logger.error("unexpected member name, " + name)
     return None
Exemplo n.º 7
0
 def getMember(self, name):
     if self.name == "by_key":
         data = _getResByKey(name)
         if data:
             return VirtualResource(joinUri(self.path, name), self.environ, data)
         else:
             return None
     return CategoryCollection(joinUri(self.path, name), self.environ, self.name)
Exemplo n.º 8
0
 def getMember(self, name):
     if self.episodes is None:
         self.extractInfo()
     try:
         url = self.episodes[name]
     except:
         return None
     if '/archives/' in url:
         return EpisodeCollection(joinUri(self.path, name), self.environ,
                                  url)
     return SeriesCollection(joinUri(self.path, name), self.environ, url)
Exemplo n.º 9
0
 def getMember(self, name):
     if name in self.genres:
         genre = name.lower().replace(' ', '-')
         return DirectoryPageCollection(joinUri(self.path, name),
                                        self.environ, genre)
     _logger.error("unexpected member name, " + name)
     return None
Exemplo n.º 10
0
 def getMember(self, name):
     if name in self.items:
         pname = '9' if name == '#' else name.lower()
         return DirectoryPageCollection(joinUri(self.path, name),
                                        self.environ, pname)
     _logger.error("unexpected member name, " + name)
     return None
Exemplo n.º 11
0
 def getMember(self, name):
     if name.isdigit():
         url = self.url + "/" + name
         return ChapterCollection(joinUri(self.path, name), self.environ,
                                  url)
     _logger.error("unexpected chapter name, " + name)
     return None
Exemplo n.º 12
0
 def getMember(self, name):
     """
     Return child resource with a given name (None, if not found).
     """
     assert self.isCollection
     return self.provider.getResourceInst(util.joinUri(self.path, name), 
                                          self.environ)
Exemplo n.º 13
0
 def getMember(self, name):
     if self.series is None:
         self.extractInfo()
     try:
         return SeriesCollection(joinUri(self.path, name), self.environ,
                                 self.series[name])
     except:
         return None
Exemplo n.º 14
0
 def getMember(self, name):
     if self.mangas is None:
         self.extractInfo()
     try:
         url = ROOT_URL + "/" + self.mangas[name]
         return MangaCollection(joinUri(self.path, name), self.environ, url)
     except:
         return None
Exemplo n.º 15
0
    def getMember(self, name):
        """Return direct collection member (DAVResource or derived).

        See DAVCollection.getMember()
        """
        path = util.joinUri(self.path, name)

        return self.provider.getResourceInst(path, self.environ)
Exemplo n.º 16
0
 def getMember(self, name):
     if name.isdigit():
         startid = int(name)
         url = ROOT_URL + "/popular/%s/%d" % (self.genre, startid)
         return DirectoryCollection(joinUri(self.path, name), self.environ,
                                    url)
     _logger.error("unexpected member name, " + name)
     return None
Exemplo n.º 17
0
    def getMember(self, name):
        """Return direct collection member (DAVResource or derived).

        See DAVCollection.getMember()
        """
        path = util.joinUri(self.path, name)

        return self.provider.getResourceInst(path, self.environ)
Exemplo n.º 18
0
 def getMember(self, name):
     if name.isdigit():
         pg = int(name)
         url = ROOT_URL + "/directory/%s/%d.htm" % (self.pname, pg)
         return DirectoryCollection(joinUri(self.path, name), self.environ,
                                    url)
     _logger.error("unexpected member name, " + name)
     return None
Exemplo n.º 19
0
	def createResourceInst(self, parent, name, environ):
		self._count_getResourceInst += 1
		try:
			res = VDOM_resource(util.joinUri(parent, name), False, environ, self.application.id, self.obj.id,None)
			res.name = name
			#res.parent = parent
			return res
		except:
			raise DAVError(HTTP_FORBIDDEN)	
Exemplo n.º 20
0
 def getMember(self, name):
     for tname, tid in self.btable:
         if tname == name:
             url = ROOT_URL + "/?c=1/%d" % tid
             url += "&sort=gid"
             #url += "&sort=subject"
             return ListPageCollection(joinUri(self.path, name),
                                       self.environ, url)
     _logger.error("unexpected member name, " + name)
     return None
Exemplo n.º 21
0
 def getMember(self, name):
     if self.galleries is None:
         self.extractInfo()
     for gid, gname in self.galleries:
         if self.name_clean(gname) == name:
             url = ROOT_URL + "/galleries/%s.html" % gid
             return GalleryCollection(joinUri(self.path, name),
                                      self.environ, url)
     _logger.warning("unexpected name, %s" % name)
     return []
Exemplo n.º 22
0
    def createCollection(self, name):
        """Create a new collection as member of self.

        See DAVResource.createCollection()
        """
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)

        path = util.joinUri(self.path, name)
        self.nibbler.mkdir(path)
Exemplo n.º 23
0
    def createCollection(self, name):
        """Create a new collection as member of self.

        See DAVResource.createCollection()
        """
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)

        path = util.joinUri(self.path, name)
        self.nibbler.mkdir(path)
Exemplo n.º 24
0
    def createCollection(self, name):
        """Create a new collection as member of self.

        See DAVResource.createCollection()
        """
        assert "/" not in name
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)
        path = util.joinUri(self.path, name)
        fp = self.provider._locToFilePath(path, self.environ)
        os.mkdir(fp)
Exemplo n.º 25
0
 def getMember(self, name):
     assert compat.is_native(name), "%r" % name
     fp = os.path.join(self._filePath, compat.to_unicode(name))
     path = util.joinUri(self.path, name)
     if os.path.isdir(fp):
         res = WTFolderResource(path, self.environ, fp, self.pathMapper)
     elif os.path.isfile(fp):
         res = WTFileResource(path, self.environ, fp, self.pathMapper)
     else:
         res = None
     return res
Exemplo n.º 26
0
	def createCollection(self, name):
		assert self.isCollection
		func_name = "createCollection"
		xml_data = """{"path": "%s", "name": "%s"}""" % (self.path, name)
		ret = managers.dispatcher.dispatch_action(self._app_id, self._obj_id, func_name, "",xml_data)
		if ret:
			res = self.provider.getResourceInst(util.joinUri(self.path, name), self.environ)
			if res:
				#get_properties.invalidate(self._app_id, self._obj_id, self.path)
				return res
		raise DAVError(HTTP_FORBIDDEN)               
Exemplo n.º 27
0
    def createEmptyResource(self, name):
        """Create an empty (length-0) resource.

        See DAVResource.createEmptyResource()
        """
        assert "/" not in name
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)
        path = util.joinUri(self.path, name)
        fp = self.provider._locToFilePath(path, self.environ)
        f = open(fp, "wb")
        f.close()
        return self.provider.getResourceInst(path, self.environ)
Exemplo n.º 28
0
    def getMember(self, name):
        """Return direct collection member (DAVResource or derived).

        See DAVCollection.getMember()
        """
        r_obj = self.dir_obj.get(name.decode("utf8"))

        path = util.joinUri(self.path, name)
        if r_obj.is_dir():
            res = FolderResource(self.nibbler, path, self.environ, r_obj)
        else:
            res = FileResource(self.nibbler, path, self.environ, r_obj)

        return res
Exemplo n.º 29
0
 def getMember(self, name):
     if self.imgurls is None:
         self.extractInfo()
     """ basename as image file name
     for url in self.imgurls:
         fname = self.basename(url)
         if fname == name:
             return ImageFile(joinUri(self.path, name), self.environ, url, self.url, self.cookie)
     return None
     """
     """ counter as image file name """
     idx = int(name.split('.')[0]) - 1
     url = self.imgurls[idx]
     return ImageFile(joinUri(self.path, name), self.environ, url, self.url,
                      self.cookie)
Exemplo n.º 30
0
    def createEmptyResource(self, name):
        """Create an empty (length-0) resource.

        See DAVResource.createEmptyResource()
        """
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)

        #if name.startswith('.'):
        #    raise DAVError(HTTP_FORBIDDEN)

        path = util.joinUri(self.path, name)
        f_obj = FSItem(name, is_dir=False) 
        self.provider.cache_fs.put(path, f_obj)
        return self.provider.getResourceInst(path, self.environ)
Exemplo n.º 31
0
    def createEmptyResource(self, name):
        """Create an empty (length-0) resource.

        See DAVResource.createEmptyResource()
        """
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)

        #if name.startswith('.'):
        #    raise DAVError(HTTP_FORBIDDEN)

        path = util.joinUri(self.path, name)
        f_obj = FSItem(name, is_dir=False)
        self.provider.cache_fs.put(path, f_obj)
        return self.provider.getResourceInst(path, self.environ)
Exemplo n.º 32
0
    def createEmptyResource(self, name):
        """Create an empty (length-0) resource.

        See DAVResource.createEmptyResource()
        """
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)

        if name.startswith('.'):
            raise DAVError(HTTP_FORBIDDEN)

        path = util.joinUri(self.path, name)
        file_md = FileMD(name.decode('utf8'))
        self.dir_obj.append(file_md)

        return self.provider.getResourceInst(path, self.environ)
Exemplo n.º 33
0
 def getMember(self, name):
     # Handle visible categories and also /by_key/...
     path = joinUri(self.path, name)
     if name == "by_language":
         return LanguageCollection(path, self.environ)
     elif name == "by_date":
         return PageCollection(path, self.environ,
                               "index-" + self.environ['hitomi.language'])
     elif name == "by_popularity":
         return PageCollection(path, self.environ,
                               "popular-" + self.environ['hitomi.language'])
     elif name == "by_artist":
         return ArtistCollection(path, self.environ)
     elif name == "by_tag":
         return TagCollection(path, self.environ)
     return []
Exemplo n.º 34
0
		def get_children(app_id, obj_id, path):
			cache.last_access = datetime.now()
			cnames = []			
			func_name = "getMembers"
			xml_data = """{"path": "%s"}""" % path
			ret = managers.dispatcher.dispatch_action(app_id, obj_id, func_name, "",xml_data) or {}
			#if ret:
			#	cnames = list(ret.keys()) if isinstance(ret, dict) else ret
			parent = cache.get((app_id, obj_id, path))
			if parent and parent[1] == 1:
				with lock:
					cache.pop((app_id, obj_id, path))
					for name,child in ret.iteritems():
						cache[(app_id, obj_id, util.joinUri(path, name))] = (child,0)
					cache[(app_id, obj_id, path)] = (parent[0], 0)
			return ret
Exemplo n.º 35
0
    def getMember(self, name):
        """Return direct collection member (DAVResource or derived).

        See DAVCollection.getMember()
        """
        assert compat.is_native(name), "%r" % name
        fp = os.path.join(self._filePath, compat.to_unicode(name))
        #        name = name.encode("utf8")
        path = util.joinUri(self.path, name)
        if os.path.isdir(fp):
            res = FolderResource(path, self.environ, fp)
        elif os.path.isfile(fp):
            res = FileResource(path, self.environ, fp)
        else:
            _logger.debug("Skipping non-file %s" % fp)
            res = None
        return res
Exemplo n.º 36
0
 def getMember(self, name):
     if self.nlist is None:
         self.nlist = pcs.list_dir_all(self.environ['bdyun.cookie'], self.environ['bdyun.tokens'], self.path)
         _dircache[self.abspath] = self.nlist
     global _video_fmts
     for item in self.nlist:
         bname = item['server_filename'].encode('utf-8')
         if bname == name:
             path = item['path'].encode('utf-8')
             if item['isdir']:
                 return BdyunCollection(path, self.environ)
             else:
                 return BdyunFile(path, self.environ, item)
         if name.endswith('.m3u8'):
             rname, ext = os.path.splitext(bname)
             if name.startswith(rname) and ext[1:].lower() in _video_fmts:
                 return BdyunStreamFile(joinUri(self.path, name), self.environ, item)
     return None
Exemplo n.º 37
0
    def testBasics(self):
        """Test basic tool functions."""
        assert joinUri("/a/b", "c") == "/a/b/c"
        assert joinUri("/a/b/", "c") == "/a/b/c"
        assert joinUri("/a/b", "c", "d") == "/a/b/c/d"
        assert joinUri("a/b", "c", "d") == "a/b/c/d"
        assert joinUri("/", "c") == "/c"
        assert joinUri("", "c") == "/c"

        assert not isChildUri("/a/b", "/a/")
        assert not isChildUri("/a/b", "/a/b")
        assert not isChildUri("/a/b", "/a/b/")
        assert not isChildUri("/a/b", "/a/bc")
        assert not isChildUri("/a/b", "/a/bc/")
        assert isChildUri("/a/b", "/a/b/c")
        assert isChildUri("/a/b", "/a/b/c")

        assert not isEqualOrChildUri("/a/b", "/a/")
        assert isEqualOrChildUri("/a/b", "/a/b")
        assert isEqualOrChildUri("/a/b", "/a/b/")
        assert not isEqualOrChildUri("/a/b", "/a/bc")
        assert not isEqualOrChildUri("/a/b", "/a/bc/")
        assert isEqualOrChildUri("/a/b", "/a/b/c")
        assert isEqualOrChildUri("/a/b", "/a/b/c")

        assert lstripstr("/dav/a/b", "/dav") == "/a/b"
        assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b"
        assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b"

        assert popPath("/a/b/c") == ("a", "/b/c")
        assert popPath("/a/b/") == ("a", "/b/")
        assert popPath("/a/") == ("a", "/")
        assert popPath("/a") == ("a", "/")
        assert popPath("/") == ("", "")
        assert popPath("") == ("", "")

        self.assertEqual(shiftPath("", "/a/b/c"), ("a", "/a", "/b/c"))
        self.assertEqual(shiftPath("/a", "/b/c"), ("b", "/a/b", "/c"))
        self.assertEqual(shiftPath("/a/b", "/c"), ("c", "/a/b/c", ""))
        self.assertEqual(shiftPath("/a/b/c", "/"), ("", "/a/b/c", ""))
        self.assertEqual(shiftPath("/a/b/c", ""), ("", "/a/b/c", ""))
Exemplo n.º 38
0
 def getMember(self, name):
     # Rely on provider to get member oinstances
     assert self.isCollection
     return self.provider.getResourceInst(util.joinUri(self.path, name), 
                                          self.environ)
Exemplo n.º 39
0
 def getMember(self, name):
     for data in _getResListByAttr(self.catType, self.name):
         if data["title"] == name:
             return VirtualResource(joinUri(self.path, name), self.environ,
                                    data)
     return None
Exemplo n.º 40
0
 def getMember(self, name):
     # Handle visible categories and also /by_key/...
     if name in self._validMemberNames:
         return CategoryTypeCollection(joinUri(self.path, name),
                                       self.environ)
     return None
Exemplo n.º 41
0
	def getMember(self, name, preloaded = None):
		assert self.isCollection
		return self.provider.getResourceInst(util.joinUri(self.path, name), 
		                                     self.environ,preloaded)	
Exemplo n.º 42
0
 def getMember(self, name):
     doc = self.coll.find_one(ObjectId(name))
     return DocResource(joinUri(self.path, name), self.environ, doc)
Exemplo n.º 43
0
 def getMember(self, name):
     coll = self.db[name]
     return CollCollection(joinUri(self.path, name), self.environ, coll)
Exemplo n.º 44
0
 def getMember(self, name):
     # Handle visible categories and also /by_key/...
     if name in self._validMemberNames:
         return CategoryTypeCollection(joinUri(self.path, name), self.environ)
     return None
Exemplo n.º 45
0
    def getMember(self, name):
#        raise NotImplementedError()
        return self.provider.getResourceInst(util.joinUri(self.path, name), 
                                             self.environ)
Exemplo n.º 46
0
 def getMember(self, name):
     for data in _getResListByAttr(self.catType, self.name):
         if data["title"] == name:
             return VirtualResource(joinUri(self.path, name), self.environ, data)
     return None
 def getMember(self, name):
     # Rely on provider to get member oinstances
     assert self.isCollection
     return self.provider.getResourceInst(util.joinUri(self.path, name), self.environ)
Exemplo n.º 48
0
 def getMember(self, name):
     doc = self.coll.find_one(ObjectId(name))
     return DocResource(joinUri(self.path, name), self.environ, doc)
Exemplo n.º 49
0
 def getMember(self, name):
     coll = self.db[name]        
     return CollCollection(joinUri(self.path, name), self.environ, coll)
Exemplo n.º 50
0
 def getMember(self, name):
     return DbCollection(joinUri(self.path, name), self.environ)