Commit ce22d919 authored by yongkangzzz's avatar yongkangzzz
Browse files

Delete print

parent 25f75e6a
......@@ -2,13 +2,19 @@ import os
import sqlite3
import random
from datetime import datetime
#This library includes functions for uploaded file management and database update
#Functions will be called by APScheduler in app.py
#Confiuration can be found in config.py
"""
This library includes functions for uploaded file management and database update
Functions will be called by APScheduler in app.py
Confiuration can be found in config.py
"""
#This method will generate a random bits(dafult to be 16) long string, which is used as the name of new user's directory
def generate_random_str(random_length=16):
"""
This method will generate a random bits(dafult to be 16) long string, which is used as the name of new user's directory
:param random_length: desired length of string
:return: randomly generated string
"""
random_str = ""
base_str = "ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789"
length = len(base_str) - 1
......@@ -16,33 +22,43 @@ def generate_random_str(random_length=16):
random_str += base_str[random.randint(0, length)]
return random_str
#This function can create a new directory which path is passed in with parameter "path"
def mkdir(path):
"""
This function can create a new directory
:param path: file path
:return: boolean:hether the directory has been created
"""
path = path.strip()
path = path.rstrip("\\")
isExists = os.path.exists(path)
if not isExists:
os.makedirs(path)
print(path + "Directory created successfully")
return True
else:
print(path + "Directory has already existed!")
return False
#This method will delete all files under "path"
def clean(path):
"""
This method will delete all files under "path"
:param path: file path
:return:
"""
clear_dir(path)
for i in os.listdir(path):
path_file = os.path.join(path, i)
os.rmdir(path_file)
print("clean finished")
#This method will delete all files and directories under "path", then delete the parent directory.
def clear_dir(path):
"""
This method will delete all files and directories under "path", then delete the parent directory.
:param path: file path
:return:
"""
isExists = os.path.exists(path)
if not isExists:
print("no such dir")
return
else:
for i in os.listdir(path):
......@@ -55,12 +71,14 @@ def clear_dir(path):
if os.path.isfile(path_file2):
os.remove(path_file2)
#Periodic method called by APScheduler in app.py.
#It can check all user information in our local database and delete all expired information.
#Additionally, check the "staitic/user" directory to erase expired directories as well.
def check_database(object):
"""
Periodic method called by APScheduler in app.py.
It can check all user information in our local database and delete all expired information.
Additionally, check the "staitic/user" directory to erase expired directories as well.
"""
db = 'user_info.sqlite3'
#db = 'sqlite:///user_info.sqlite3'
con = sqlite3.connect(db)
cur = con.cursor()
select_sql = "select file_name,expired_time,id,ip_addr from user_info"
......@@ -82,8 +100,6 @@ def check_database(object):
for dir in os.listdir("./static/user"):
flag = 0
for row in date_set:
print(row)
print(type(row[2]))
if dir == row[0] and datetime.now() < datetime.strptime(row[1], "%Y-%m-%d %H:%M:%S.%f"):
flag = 1
if flag == 0:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment