Пример #1
0
 def testUpgradeTo0_20(self):
     """
     Creates a package similar to what 0.19 would
     and tests if it upgrades ok
     """
     fn = Path('0.19 resources upgrade test.elp')
     assert fn.isfile() or fn.islink()
     package = self.package.__class__.load(fn)
     assert hasattr(package, 'resources')
     assert len(package.resources) == 8, len(package.resources)
     for checksum, resources in package.resources.items():
         storageNames = []
         userNames = []
         for res in resources:
             storageNames.append(res.storageName)
             userNames.append(res.userName)
         assert len(set(storageNames)) == 1, 'Two identical resources have different storage names:\n%s' % storageNames
     allResourceNames = []
     for reses in package.resources.values():
         allResourceNames.append(reses[0].storageName)
     filenames = [path.basename() for path in package.resourceDir.files()]
     withoutDups = set(filenames) - set(allResourceNames)
     assert withoutDups == set([]), "Duplicate files weren't deleted %s" % withoutDups
     assert len(filenames) == len(allResourceNames)
     assert len(filenames) > 0, 'All resources have been deleted!'
Пример #2
0
 def testUpgradeTo0_20(self):
     """
     Creates a package similar to what 0.19 would
     and tests if it upgrades ok
     """
     fn = Path('0.19 resources upgrade test.elp')
     assert fn.isfile() or fn.islink()
     package = self.package.__class__.load(fn)
     assert hasattr(package, 'resources')
     assert len(package.resources) == 8, len(package.resources)
     for checksum, resources in package.resources.items():
         storageNames = []
         userNames = []
         for res in resources:
             storageNames.append(res.storageName)
             userNames.append(res.userName)
         assert len(
             set(storageNames)
         ) == 1, 'Two identical resources have different storage names:\n%s' % storageNames
     allResourceNames = []
     for reses in package.resources.values():
         allResourceNames.append(reses[0].storageName)
     filenames = [path.basename() for path in package.resourceDir.files()]
     withoutDups = set(filenames) - set(allResourceNames)
     assert withoutDups == set(
         []), "Duplicate files weren't deleted %s" % withoutDups
     assert len(filenames) == len(allResourceNames)
     assert len(filenames) > 0, 'All resources have been deleted!'
Пример #3
0
    def render(self, request):
        if "sendWhat" in request.args:
            if request.args['sendWhat'][0] == 'dirs':
                pathdir = Path(unquote(request.args['node'][0].decode('utf-8')))
                l = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for d in get_drives():
                        try:
                            if is_readable(Path(d)):
                                icon = None
                            else:
                                icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                            l.append({"realtext": d, "text": d, "id": d + '\\', "icon": icon})
                        except:
                            pass
                else:
                    for d in pathdir.dirs():
                        try:
                            if not d.name.startswith('.') or sys.platform[:3] == "win":
                                if not iswinlink(d.abspath()):
                                    if is_readable(d):
                                        icon = None
                                    else:
                                        icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                                    l.append({"realtext": d.name, "text": getname(d), "id": d.abspath(), "icon": icon})
                        except:
                            pass
            elif request.args['sendWhat'][0] == 'both':
                pathdir = Path(unquote(request.args['dir'][0].decode('utf-8')))
                items = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for drive in get_drives():
                        d = Path(drive + '\\')
                        items.append({"name": drive, "realname": drive + '\\', "size": 0, "type": 'directory', "modified": 0,
                                      "is_readable": is_readable(d),
                                      "is_writable": is_writable(d)})
                else:
                    parent = pathdir.parent
                    if (parent == pathdir):
                        realname = '/'
                    else:
                        realname = parent.abspath()
                    items.append({"name": '.', "realname": pathdir.abspath(), "size": pathdir.size, "type": "directory", "modified": int(pathdir.mtime),
                                  "is_readable": is_readable(pathdir),
                                  "is_writable": is_writable(pathdir)})
                    items.append({"name": '..', "realname": realname, "size": parent.size, "type": "directory", "modified": int(parent.mtime),
                                  "is_readable": is_readable(parent),
                                  "is_writable": is_writable(parent)})
                    try:
                        for d in pathdir.listdir():
                            try:
                                if not d.name.startswith('.') or sys.platform[:3] == "win":
                                    if not iswinlink(d.abspath()):
                                        if d.isdir():
                                            pathtype = "directory"
                                        elif d.isfile():
                                            if is_readable(d):
                                                pathtype = repr(mimetypes.guess_type(d.name, False)[0])
                                            else:
                                                pathtype = "file"
                                        elif d.islink():
                                            pathtype = "link"
                                        else:
                                            pathtype = "None"
                                        items.append({"name": getname(d), "realname": d.abspath(), "size": d.size, "type": pathtype, "modified": int(d.mtime),
                                          "is_readable": is_readable(d),
                                          "is_writable": is_writable(d)})
                            except:
                                pass
                        G.application.config.lastDir = pathdir
                    except:
                        pass
                l = {"totalCount": len(items), 'results': len(items), 'items': items}
            return json.dumps(l).encode('utf-8')
        elif "query" in request.args:
            query = request.args['query'][0]
            pathdir = Path(unquote(request.args['dir'][0].decode('utf-8')))
            items = []
            if pathdir == '/' and sys.platform[:3] == "win":
                for d in get_drives():
                    items.append({"name": d, "realname": d + '\\', "size": 0, "type": 'directory', "modified": 0})
            else:
                parent = pathdir.parent
                if (parent == pathdir):
                    realname = '/'
                else:
                    realname = parent.abspath()
                for d in pathdir.listdir():
                    try:
                        if d.isdir():
                            pathtype = "directory"
                        elif d.isfile():
                            if is_readable(d):
                                pathtype = repr(mimetypes.guess_type(d.name, False)[0])
                            else:
                                pathtype = "file"
                        elif d.islink():
                            pathtype = "link"
                        else:
                            pathtype = "None"
                        if d.name.startswith(query):
                            items.append({"name": getname(d), "realname": d.abspath(), "size": d.size, "type": pathtype, "modified": int(d.mtime),
                                          "is_readable": is_readable(d),
                                          "is_writable": is_writable(d)})
                    except:
                        pass

            l = {"totalCount": len(items), 'results': len(items), 'items': items}
            return json.dumps(l).encode('utf-8')
        return ""
Пример #4
0
    def render(self, request):
        if "sendWhat" in request.args:
            if request.args['sendWhat'][0] == 'dirs':
                pathdir = Path(unquote(
                    request.args['node'][0].decode('utf-8')))
                l = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for d in get_drives():
                        try:
                            if is_readable(Path(d)):
                                icon = None
                            else:
                                icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                            l.append({
                                "realtext": d,
                                "text": d,
                                "id": d + '\\',
                                "icon": icon
                            })
                        except:
                            pass
                else:
                    for d in pathdir.dirs():
                        try:
                            if not d.name.startswith(
                                    '.') or sys.platform[:3] == "win":
                                if not iswinlink(d.abspath()):
                                    if is_readable(d):
                                        icon = None
                                    else:
                                        icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                                    l.append({
                                        "realtext": d.name,
                                        "text": getname(d),
                                        "id": d.abspath(),
                                        "icon": icon
                                    })
                        except:
                            pass
            elif request.args['sendWhat'][0] == 'both':
                pathdir = Path(unquote(request.args['dir'][0].decode('utf-8')))
                items = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for drive in get_drives():
                        d = Path(drive + '\\')
                        items.append({
                            "name": drive,
                            "realname": drive + '\\',
                            "size": 0,
                            "type": 'directory',
                            "modified": 0,
                            "is_readable": is_readable(d),
                            "is_writable": is_writable(d)
                        })
                else:
                    parent = pathdir.parent
                    if (parent == pathdir):
                        realname = '/'
                    else:
                        realname = parent.abspath()
                    items.append({
                        "name": '.',
                        "realname": pathdir.abspath(),
                        "size": pathdir.size,
                        "type": "directory",
                        "modified": int(pathdir.mtime),
                        "is_readable": is_readable(pathdir),
                        "is_writable": is_writable(pathdir)
                    })
                    items.append({
                        "name": '..',
                        "realname": realname,
                        "size": parent.size,
                        "type": "directory",
                        "modified": int(parent.mtime),
                        "is_readable": is_readable(parent),
                        "is_writable": is_writable(parent)
                    })
                    try:
                        for d in pathdir.listdir():
                            try:
                                if not d.name.startswith(
                                        '.') or sys.platform[:3] == "win":
                                    if not iswinlink(d.abspath()):
                                        if d.isdir():
                                            pathtype = "directory"
                                        elif d.isfile():
                                            if is_readable(d):
                                                pathtype = repr(
                                                    mimetypes.guess_type(
                                                        d.name, False)[0])
                                            else:
                                                pathtype = "file"
                                        elif d.islink():
                                            pathtype = "link"
                                        else:
                                            pathtype = "None"
                                        items.append({
                                            "name":
                                            getname(d),
                                            "realname":
                                            d.abspath(),
                                            "size":
                                            d.size,
                                            "type":
                                            pathtype,
                                            "modified":
                                            int(d.mtime),
                                            "is_readable":
                                            is_readable(d),
                                            "is_writable":
                                            is_writable(d)
                                        })
                            except:
                                pass
                        G.application.config.lastDir = pathdir
                    except:
                        pass
                l = {
                    "totalCount": len(items),
                    'results': len(items),
                    'items': items
                }
            return json.dumps(l).encode('utf-8')
        elif "query" in request.args:
            query = request.args['query'][0]
            pathdir = Path(unquote(request.args['dir'][0].decode('utf-8')))
            items = []
            if pathdir == '/' and sys.platform[:3] == "win":
                for d in get_drives():
                    items.append({
                        "name": d,
                        "realname": d + '\\',
                        "size": 0,
                        "type": 'directory',
                        "modified": 0
                    })
            else:
                parent = pathdir.parent
                if (parent == pathdir):
                    realname = '/'
                else:
                    realname = parent.abspath()
                for d in pathdir.listdir():
                    try:
                        if d.isdir():
                            pathtype = "directory"
                        elif d.isfile():
                            if is_readable(d):
                                pathtype = repr(
                                    mimetypes.guess_type(d.name, False)[0])
                            else:
                                pathtype = "file"
                        elif d.islink():
                            pathtype = "link"
                        else:
                            pathtype = "None"
                        if d.name.startswith(query):
                            items.append({
                                "name": getname(d),
                                "realname": d.abspath(),
                                "size": d.size,
                                "type": pathtype,
                                "modified": int(d.mtime),
                                "is_readable": is_readable(d),
                                "is_writable": is_writable(d)
                            })
                    except:
                        pass

            l = {
                "totalCount": len(items),
                'results': len(items),
                'items': items
            }
            return json.dumps(l).encode('utf-8')
        return ""
    def render(self, request):
        if "sendWhat" in request.args:
            if request.args['sendWhat'][0] == 'dirs':
                #Because this might be absolute and mess up...
                
                
                path_dir_str = unquote(request.args['node'][0].decode('utf-8'))
                path_dir_str = self.get_dirpath_for_request(
                                                request, path_dir_str)
                pathdir = Path(path_dir_str)
                
                
                l = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for d in get_drives():
                        try:
                            if is_readable(Path(d)):
                                icon = None
                            else:
                                icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                            l.append({"realtext": d, "text": d, "id": d + '\\', "icon": icon})
                        except:
                            pass
                else:
                    for d in pathdir.dirs():
                        try:
                            if not d.name.startswith('.') or sys.platform[:3] == "win":
                                if not iswinlink(d.abspath()):
                                    if is_readable(d):
                                        icon = None
                                    else:
                                        icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                                    l.append({"realtext": d.name, "text": getname(d), "id": self.abs_to_user_path(d.abspath(), request), "icon": icon})
                        except:
                            pass
            elif request.args['sendWhat'][0] == 'both':
                req_pathdir_str = unquote(request.args['dir'][0].decode('utf-8'))
                pathdir_str = self.get_dirpath_for_request(
                                               request, req_pathdir_str)
                pathdir = Path(pathdir_str)
                items = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for drive in get_drives():
                        d = Path(drive + '\\')
                        items.append({"name": drive, "realname": drive + '\\', "size": 0, "type": 'directory', "modified": 0,
                                      "is_readable": is_readable(d),
                                      "is_writable": is_writable(d)})
                else:
                    parent = pathdir.parent
                    if (parent == pathdir):
                        realname = '/'
                    else:
                        realname = self.abs_to_user_path(parent.abspath(), request)
                    items.append({"name": '.', "realname": self.abs_to_user_path(pathdir.abspath(), request), "size": pathdir.size, "type": "directory", "modified": int(pathdir.mtime),
                                  "is_readable": is_readable(pathdir),
                                  "is_writable": is_writable(pathdir)})
                    items.append({"name": '..', "realname": realname, "size": parent.size, "type": "directory", "modified": int(parent.mtime),
                                  "is_readable": is_readable(parent),
                                  "is_writable": is_writable(parent)})
                    try:
                        for d in pathdir.listdir():
                            try:
                                if not d.name.startswith('.') or sys.platform[:3] == "win":
                                    if not iswinlink(d.abspath()):
                                        if d.isdir():
                                            pathtype = "directory"
                                        elif d.isfile():
                                            if is_readable(d):
                                                pathtype = repr(mimetypes.guess_type(d.name, False)[0])
                                            else:
                                                pathtype = "file"
                                        elif d.islink():
                                            pathtype = "link"
                                        else:
                                            pathtype = "None"
                                        items.append({"name": getname(d), "realname": self.abs_to_user_path(d.abspath(), request), "size": d.size, "type": pathtype, "modified": int(d.mtime),
                                          "is_readable": is_readable(d),
                                          "is_writable": is_writable(d)})
                            except:
                                pass
                        #this was before just pathdir - check this
                        if G.application.config.appMode != Config.MODE_WEBAPP:
                            G.application.config.lastDir = pathdir
                        else:
                            self.session.webservice_config.lastDir = req_pathdir_str
                    except:
                        pass
                l = {"totalCount": len(items), 'results': len(items), 'items': items}
            return json.dumps(l).encode('utf-8')
        elif "query" in request.args:
            query = request.args['query'][0]
            path_dir_str = unquote(request.args['dir'][0].decode('utf-8'))
            path_dir_str = self.get_dirpath_for_request(request,path_dir_str)
            pathdir = Path(path_dir_str)
            items = []
            if pathdir == '/' and sys.platform[:3] == "win":
                for d in get_drives():
                    items.append({"name": d, "realname": d + '\\', "size": 0, "type": 'directory', "modified": 0})
            else:
                parent = pathdir.parent
                if (parent == pathdir):
                    realname = '/'
                else:
                    realname = self.abs_to_user_path(parent.abspath(), request)
                for d in pathdir.listdir():
                    try:
                        if d.isdir():
                            pathtype = "directory"
                        elif d.isfile():
                            if is_readable(d):
                                pathtype = repr(mimetypes.guess_type(d.name, False)[0])
                            else:
                                pathtype = "file"
                        elif d.islink():
                            pathtype = "link"
                        else:
                            pathtype = "None"
                        if d.name.startswith(query):
                            items.append({"name": getname(d), "realname": self.abs_to_user_path(d.abspath(), request), "size": d.size, "type": pathtype, "modified": int(d.mtime),
                                          "is_readable": is_readable(d),
                                          "is_writable": is_writable(d)})
                    except:
                        pass

            l = {"totalCount": len(items), 'results': len(items), 'items': items}
            return json.dumps(l).encode('utf-8')
        elif "uploadfileaction" in request.args:
            filename = request.args["upload_file_name"][0]
            current_dir = request.args["upload_current_dir"][0]
            save_path = os.path.join(current_dir, filename)
            file_path =  self.get_dirpath_for_request(
                                                request, save_path)
            file = open(file_path, "wb")
            file.write(request.args['upload_file'][0])
            file.close()
            
            result = {"success" : True}
            return json.dumps(result).encode('utf-8')
        return ""