示例#1
0
 def test_view_source_update(self):
     json_request("/code/view_source/update",
                  method="POST",
                  data=dict(path="./test.md", content="hello"))
     content = xutils.readfile("./test.md")
     self.assertEqual("hello", content)
     xutils.remove("./test.md", hard=True)
示例#2
0
    def POST(self):
        file = web.input(file={}).file
        filename = file.filename
        parent = config.APP_DIR

        basename, ext = os.path.splitext(filename)
        if ext != ".zip":
            return self.GET("Expect zip file!")

        filepath = os.path.join(parent, filename)
        with open(filepath, "wb") as fp:
            for chunk in file.file:
                fp.write(chunk)
        # 解压文件

        basename, ext = os.path.splitext(filename)
        app_dir = os.path.join(parent, basename)
        error = ""

        try:
            # 删除旧文件
            if os.path.exists(app_dir):
                xutils.remove(app_dir)
            # mode只有'r', 'w', 'a'
            zf = zipfile.ZipFile(filepath, "r")
            zf.extractall(app_dir)
        except Exception as e:
            error = str(e)
        return self.GET(error)
示例#3
0
文件: fs.py 项目: licshire/xnote
 def POST(self):
     path = xutils.get_argument("path")
     try:
         xutils.remove(path)
         return dict(code="success")
     except Exception as e:
         xutils.print_exc()
         return dict(code="fail", message=str(e))
示例#4
0
 def merge_files(self, dirname, filename, chunks):
     dest_path = os.path.join(dirname, filename)
     with open(dest_path, "wb") as fp:
         for chunk in range(chunks):
             tmp_path = os.path.join(dirname, filename)
             tmp_path = "%s_%d.part" % (tmp_path, chunk)
             if not os.path.exists(tmp_path):
                 raise Exception("upload file broken")
             with open(tmp_path, "rb") as tmp_fp:
                 fp.write(tmp_fp.read())
             xutils.remove(tmp_path, True)
示例#5
0
    def test_script_rename(self):
        path1 = get_script_path("unit-test-1.py")
        path2 = get_script_path("unit-test-2.py")
        xutils.remove(path1, hard = True)
        xutils.remove(path2, hard = True)

        ret = json_request("/system/script/rename?oldname=unit-test-1.py&newname=unit-test-2.py", method="POST")
        self.assertEqual("fail", ret["code"])

        xutils.touch(path1)
        ret = json_request("/system/script/rename?oldname=unit-test-1.py&newname=unit-test-2.py", method="POST")
        self.assertEqual("success", ret["code"])
示例#6
0
 def merge_files(self, dirname, filename, chunks):
     dest_path = os.path.join(dirname, filename)
     user_name = xauth.current_name()
     with open(dest_path, "wb") as fp:
         for chunk in range(chunks):
             tmp_path = os.path.join(dirname, filename)
             tmp_path = "%s_%d.part" % (tmp_path, chunk)
             if not os.path.exists(tmp_path):
                 raise Exception("upload file broken")
             with open(tmp_path, "rb") as tmp_fp:
                 fp.write(tmp_fp.read())
             xutils.remove(tmp_path, True)
         xmanager.fire("fs.upload", dict(user=user_name, path=dest_path))
示例#7
0
文件: fs.py 项目: ydx2099/xnote
 def POST(self):
     path = xutils.get_argument("path")
     user_name = xauth.current_name()
     if not xauth.is_admin() and not check_file_auth(path, user_name):
         return dict(code="fail", message="unauthorized")
     try:
         if not os.path.exists(path):
             basename = os.path.basename(path)
             return dict(code="fail", message="源文件`%s`不存在" % basename)
         xutils.remove(path)
         xmanager.fire("fs.remove", Storage(user=user_name, path=path))
         return dict(code="success")
     except Exception as e:
         xutils.print_exc()
         return dict(code="fail", message=str(e))
示例#8
0
 def GET(self):
     parent = xconfig.APP_DIR
     name = xutils.get_argument("name")
     if name == "" or name is None:
         raise web.seeother("/system/app_admin")
     # name = xutils.unquote(name)
     name = xutils.quote_unicode(name)
     basename, ext = os.path.splitext(name)
     if ext != ".zip":
         raise web.seeother("/system/app_admin?error=EXPECT_ZIP")
     app_dir = os.path.join(parent, basename)
     filepath = os.path.join(parent, name)
     error = ""
     try:
         # 删除旧文件
         if os.path.exists(app_dir):
             xutils.remove(app_dir)
         # mode只有'r', 'w', 'a'
         zf = zipfile.ZipFile(filepath, "r")
         zf.extractall(app_dir)
     except Exception as e:
         error = str(e)
     raise web.seeother("/system/app_admin?error=" + error)
示例#9
0
 def test_save_file(self):
     tmpfile = os.path.join(xconfig.DATA_DIR, "tmp.txt")
     xutils.savetofile(tmpfile, "test")
     content = xutils.readfile(tmpfile)
     self.assertEqual("test", content)
     xutils.remove(tmpfile, True)