-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
directory watcher was replaced by a queue
- Loading branch information
Showing
8 changed files
with
108 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
'''mgxhub main source code''' | ||
|
||
import queue | ||
|
||
from .config import cfg | ||
from .logger import logger | ||
from .db import db | ||
from .logger import logger | ||
|
||
proc_queue = queue.Queue() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'''Scan a directory in upload dir and put file to process queue''' | ||
|
||
import os | ||
|
||
from mgxhub import proc_queue | ||
|
||
|
||
def scan(dirpath: str): | ||
'''Scan a directory in upload dir and put file to process queue | ||
Args: | ||
dirpath (str): The directory path to scan. | ||
''' | ||
|
||
for root, dirs, files in os.walk(dirpath, topdown=False): | ||
for filename in files: | ||
file_path = os.path.join(root, filename) | ||
proc_queue.put(file_path) # Processor will tried to remove empty parent directory. | ||
for dir in dirs: | ||
# Try remove the directory if it is empty, this works because topdown=False | ||
current_dir_path = os.path.join(root, dir) | ||
if os.path.isdir(current_dir_path) and not os.listdir(current_dir_path): | ||
try: | ||
os.rmdir(current_dir_path) | ||
except OSError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# GPT generated script not revised yet. | ||
|
||
import os | ||
import shutil | ||
|
||
from sqlalchemy import MetaData, Table, create_engine, select | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
# 创建SQLite数据库引擎 | ||
engine = create_engine('sqlite:///migrate_20240411190857.db') | ||
|
||
# 创建Session | ||
Session = sessionmaker(bind=engine) | ||
session = Session() | ||
|
||
# 获取log表的元数据 | ||
metadata = MetaData() | ||
log_table = Table('log', metadata, autoload_with=engine) | ||
|
||
# 查询所有message不为空的记录 | ||
query = select(log_table).where(log_table.c.message != None) | ||
results = session.execute(query) | ||
|
||
# 创建exceptions文件夹 | ||
exceptions_dir = os.path.join(os.getcwd(), 'exception') | ||
os.makedirs(exceptions_dir, exist_ok=True) | ||
|
||
# 复制文件 | ||
for result in results: | ||
srcfile = result['srcfile'] | ||
if srcfile: | ||
dstfile = os.path.join(exceptions_dir, srcfile) | ||
shutil.copyfile(f"/records/{srcfile}", dstfile) |