def GET(self): op = xutils.get_argument("op") name = xutils.get_argument("name", "") error = xutils.get_argument("error", "") dirname = xconfig.SCRIPTS_DIR content = "" if op == "edit": content = xutils.readfile(os.path.join(dirname, name)) if op == "add" and name != "": path = os.path.join(dirname, name) basename, ext = os.path.splitext(name) if ext not in SCRIPT_EXT_LIST: name = basename + get_default_shell_ext() path = os.path.join(dirname, name) if os.path.exists(path): raise web.seeother( xutils.quote_unicode("/system/script_admin?error=%r已存在" % name)) xutils.touch(path) shell_list = get_script_list() return xtemplate.render(template_file, op=op, name=name, content=content, shell_list=shell_list, error=error)
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"])
def create_file(self, path): xutils.touch(path)
def create_file(self, path): if os.path.exists(path): name = os.path.basename(path) raise Exception("file [%s] exists" % name) xutils.touch(path)
def create_tmp_file(name): path = os.path.join(xconfig.DATA_DIR, "files", "user", "upload", time.strftime("%Y/%m"), name) xutils.touch(path)
def create_file(self, path): if os.path.exists(path): raise Exception("file exists") xutils.touch(path)