def POST(self): script_url = xutils.get_argument("script_url") url = xutils.get_argument("url") # url = xutils.quote_unicode(url) tm_wday = xutils.get_argument("tm_wday") tm_hour = xutils.get_argument("tm_hour") tm_min = xutils.get_argument("tm_min") format = xutils.get_argument("_format") if script_url != "" and script_url != None: url = script_url if url == "": raise web.seeother("/system/crontab") sched_id = add_cron_task(url=url, ctime=xutils.format_time(), mtime=xutils.format_time(), tm_wday=tm_wday, tm_hour=tm_hour, tm_min=tm_min) xmanager.instance().load_tasks() if format == "json": return dict(code="success", data=dict(id=sched_id)) raise web.seeother("/system/crontab")
def add_user(name, password): if name == "" or name == None: return if password == "" or password == None: return if not is_valid_username(name): return dict(code="INVALID_NAME", message="非法的用户名") name = name.lower() found = find_by_name(name) if found is not None: found.mtime = xutils.format_time() found.salt = textutil.random_string(6) found.token = gen_new_token() found.password = password update_user(name, found) else: user = Storage(name=name, password=password, token=gen_new_token(), ctime=xutils.format_time(), salt=textutil.random_string(6), mtime=xutils.format_time()) dbutil.put("user:%s" % name, user) xutils.trace("UserAdd", name) refresh_users()
def search(delay_mins, message): if not xauth.is_admin(): return [] db = xtables.get_schedule_table() url = "/api/alarm/" + message millis = time.time() + int(delay_mins) * 60 tm = time.localtime(millis) tm_wday = "no-repeat" tm_hour = tm.tm_hour tm_min = tm.tm_min db.insert(url=url, ctime=xutils.format_time(), mtime=xutils.format_time(), tm_wday=tm_wday, tm_hour=tm_hour, tm_min=tm_min) xmanager.load_tasks() result = SearchResult() result.name = "提醒" result.raw = "提醒创建成功,将于%s提醒 %s" % (xutils.format_time(millis), message) return [result]
def add_request_old(self): url = xutils.get_argument("url") # interval = xutils.get_argument("interval", 10, type=int) repeat_type = xutils.get_argument("repeat_type", "day") pattern = xutils.get_argument("pattern") if repeat_type == "interval": interval = int(pattern) else: interval = -1 if pattern.count(":") == 1: # 如果是分钟默认加上秒 pattern = pattern + ":00" db = xtables.get_schedule_table() rows = db.select(where="url=$url", vars=dict(url=url)) result = rows.first() if result is None: db.insert(url=url, interval=interval, pattern=pattern, ctime=xutils.format_time(), mtime=xutils.format_time(), repeat_type=repeat_type) else: db.update(where=dict(url=url), interval=interval, pattern=pattern, mtime=xutils.format_time(), repeat_type=repeat_type) xmanager.instance().load_tasks() raise web.seeother("/system/crontab")
def add_user(name, password): users = _get_users() user = Storage(name=name, password=password) users[name] = user db = xtables.get_user_table() exist = db.select_one(where=dict(name=name)) if exist is None: db.insert(name=name,password=password,ctime=xutils.format_time(),mtime=xutils.format_time()) else: db.update(where=dict(name=name), password=password,mtime=xutils.format_time())
def add_user(name, password): db = xtables.get_user_table() exist = db.select_one(where=dict(name=name)) if exist is None: db.insert(name=name, password=password, token=gen_new_token(), ctime=xutils.format_time(), mtime=xutils.format_time()) else: db.update(where=dict(name=name), password=password, token=gen_new_token(), mtime=xutils.format_time()) refresh_users()
def add_alarm(tm_hour, tm_min, message): db = xtables.get_schedule_table() url = "/api/alarm" tm_wday = "no-repeat" name = "[提醒] %s" % message db.insert(name=name, url=url, message=message, ctime=xutils.format_time(), mtime=xutils.format_time(), tm_wday=tm_wday, tm_hour=tm_hour, tm_min=tm_min) xmanager.load_tasks()
def update_note(note_id, **kw): # 这里只更新基本字段,移动笔记使用 move_note content = kw.get('content') data = kw.get('data') priority = kw.get('priority') name = kw.get("name") atime = kw.get("atime") is_public = kw.get("is_public") tags = kw.get("tags") orderby = kw.get("orderby") archived = kw.get("archived") size = kw.get("size") token = kw.get("token") visited_cnt = kw.get("visited_cnt") old_parent_id = None new_parent_id = None note = get_by_id(note_id) if note: if content: note.content = content if data: note.data = data if priority != None: note.priority = priority if name: note.name = name if atime: note.atime = atime if is_public != None: note.is_public = is_public if tags != None: note.tags = tags if orderby != None: note.orderby = orderby if archived != None: note.archived = archived if size != None: note.size = size if token != None: note.token = token if visited_cnt != None: note.visited_cnt = visited_cnt old_version = note.version note.mtime = xutils.format_time() note.version += 1 # 只修改优先级 if len(kw) == 1 and kw.get('priority') != None: note.version = old_version # 只修改名称 if len(kw) == 1 and kw.get('name') != None: note.version = old_version kv_put_note(note_id, note) return 1 return 0
def add_user(name, password): if name == "" or name == None: return if password == "" or password == None: return db = xtables.get_user_table() exist = db.select_one(where=dict(name=name)) if exist is None: db.insert(name=name,password=password, token=gen_new_token(), ctime=xutils.format_time(), salt=textutil.random_string(6), mtime=xutils.format_time()) else: db.update(where=dict(name=name), password=password, token=gen_new_token(), salt=textutil.random_string(6), mtime=xutils.format_time()) refresh_users()
def POST(self): note_id = xutils.get_argument("note_id") content = xutils.get_argument("content") user = xauth.current_name() NOTE_DAO.save_comment( dict(note_id=note_id, ctime=xutils.format_time(), user=user, content=content)) return dict(success=True)
def POST(self): content = xutils.get_argument("content") user = xauth.get_current_user() # chatlist.append(content) db = xtables.get_message_table() ctime = xutils.format_time() db.insert(user=user.get("name"), ctime=ctime, content=content) return dict(code="success", message="", data=dict(user=user.get("name"), content=content, ctime=ctime))
def search(mute_last): if mute_last == "": last = 3 * 60 elif mute_last.endswith("小时"): pattern = r"(\d+)" match = re.match(pattern, mute_last).group(0) last = int(match) * 60 xconfig.MUTE_END_TIME = time.time() + last * 60 result = xutils.SearchResult() result.name = "命令 - 静音" result.raw = "静音到 %s" % xutils.format_time(xconfig.MUTE_END_TIME) return [result]
def add_user(name, password): if name == "" or name == None: return if password == "" or password == None: return if not is_valid_username(name): return dict(code="INVALID_NAME", message="非法的用户名") db = xtables.get_user_table() exist = db.select_first(where=dict(name=name)) if exist is None: db.insert(name=name,password=password, token=gen_new_token(), ctime=xutils.format_time(), salt=textutil.random_string(6), mtime=xutils.format_time()) else: db.update(where=dict(name=name), password=password, token=gen_new_token(), salt=textutil.random_string(6), mtime=xutils.format_time()) refresh_users()
def add_user(name, password): if name == "" or name == None: return dict(code="PARAM_ERROR", message="name为空") if password == "" or password == None: return dict(code="PARAM_ERROR", message="password为空") if not is_valid_username(name): return dict(code="INVALID_NAME", message="非法的用户名") name = name.lower() found = find_by_name(name) if found is not None: return dict(code="fail", message="用户已存在") else: user = Storage(name=name, password=password, token=gen_new_token(), ctime=xutils.format_time(), salt=textutil.random_string(6), mtime=xutils.format_time()) dbutil.put("user:%s" % name, user) xutils.trace("UserAdd", name) refresh_users() return dict(code="success", message="create success")
def POST(self): script_url = xutils.get_argument("script_url") url = xutils.get_argument("url") # url = xutils.quote_unicode(url) tm_wday = xutils.get_argument("tm_wday") tm_hour = xutils.get_argument("tm_hour") tm_min = xutils.get_argument("tm_min") if script_url != "" and script_url != None: url = script_url if url == "": raise web.seeother("/system/crontab") db = xtables.get_schedule_table() db.insert(url=url, ctime=xutils.format_time(), mtime=xutils.format_time(), tm_wday=tm_wday, tm_hour=tm_hour, tm_min=tm_min) xmanager.instance().load_tasks() raise web.seeother("/system/crontab")
def chk_backup(): backup_dir = xconfig.BACKUP_DIR xutils.makedirs(backup_dir) files = os.listdir(backup_dir) sorted_files = sorted(files) logutil.info("sorted backup files: {}", sorted_files) for fname in sorted_files: path = os.path.join(backup_dir, fname) ctime = os.stat(path).st_ctime print("%s - %s" % (path, xutils.format_time(ctime))) tm = time.localtime() if tm.tm_wday != 5: print("not the day, quit") # 一周备份一次 return if _remove_old and len(sorted_files) > _MAX_BACKUP_COUNT: target = sorted_files[0] target_path = os.path.join(backup_dir, target) fsutil.remove(target_path) logutil.warn("remove file {}", target_path) if len(sorted_files) == 0: backup_db() else: lastfile = sorted_files[-1] p = re.compile(r"data\.(\d+)\.db") m = p.match(lastfile) if m: data = m.groups()[0] tm_time = time.strptime(data, "%Y%m%d") seconds = time.mktime(tm_time) now = time.time() # backup every 10 days. if now - seconds > _BACKUP_INTERVAL: backup_db() else: # 先创建一个再删除 backup_db() lastfile_path = os.path.join(backup_dir, lastfile) fsutil.remove(lastfile_path) logutil.warn("not valid db backup file, remove {}", lastfile_path)
def update_note(where, **kw): note_id = where['id'] creator = where.get('creator') content = kw.get('content') data = kw.get('data') priority = kw.get('priority') name = kw.get("name") atime = kw.get("atime") parent_id = kw.get("parent_id") is_public = kw.get("is_public") tags = kw.get("tags") orderby = kw.get("orderby") archived = kw.get("archived") old_parent_id = None new_parent_id = None note = get_by_id(note_id) if note: if creator and note.creator != creator: return 0 if content: note.content = content if data: note.data = data if priority != None: note.priority = priority if name: note.name = name if atime: note.atime = atime if parent_id != None: old_parent_id = note.parent_id new_parent_id = parent_id note.parent_id = parent_id if is_public != None: note.is_public = is_public if tags != None: note.tags = tags if orderby != None: note.orderby = orderby if archived != None: note.archived = archived old_version = note.version note.mtime = xutils.format_time() note.version += 1 # 只修改优先级 if len(kw) == 1 and kw.get('priority') != None: note.version = old_version # 只修改名称 if len(kw) == 1 and kw.get('name') != None: note.version = old_version kv_put_note(note_id, note) # 处理移动分类时的统计 if new_parent_id != None and new_parent_id != old_parent_id: update_children_count(old_parent_id) update_children_count(new_parent_id) # 更新parent更新时间 touch_note(note.parent_id) return 1 return 0
def kv_update_note(where, **kw): note_id = where['id'] creator = where.get('creator') content = kw.get('content') data = kw.get('data') priority = kw.get('priority') name = kw.get("name") atime = kw.get("atime") parent_id = kw.get("parent_id") is_public = kw.get("is_public") tags = kw.get("tags") old_parent_id = None new_parent_id = None note = get_by_id(note_id) if note: if creator and note.creator != creator: return 0 if content: note.content = content if data: note.data = data if priority != None: note.priority = priority if name: note.name = name if atime: note.atime = atime if parent_id != None: old_parent_id = note.parent_id new_parent_id = parent_id note.parent_id = parent_id if is_public != None: note.is_public = is_public if tags != None: note.tags = tags note.mtime = xutils.format_time() note.version += 1 # 只修改优先级 if len(kw) == 1 and kw.get('priority') != None: note.version -= 1 # 只修改名称 if len(kw) == 1 and kw.get('name') != None: note.version -= 1 kv_put_note(note_id, note) # 处理移动分类时的统计 if new_parent_id != None and new_parent_id != old_parent_id: update_children_count(old_parent_id) update_children_count(new_parent_id) old_dirname = os.path.join(xconfig.UPLOAD_DIR, note.creator, str(old_parent_id), str(note.id)) new_dirname = os.path.join(xconfig.UPLOAD_DIR, note.creator, str(new_parent_id), str(note.id)) fsutil.mvfile(old_dirname, new_dirname) return 1 return 0