refactor: 8 个 workspace dspy 内联重复逻辑收敛到 get_workspace_dir/get_workspace_base
This commit is contained in:
parent
f68755edf8
commit
b9a458af53
@ -202,13 +202,7 @@ async def _exec_tool(sor, tool, params, ctx, uid, org_id):
|
||||
if ex: return f'FAIL: 项目「{name}」已存在'
|
||||
pid = getID()
|
||||
wid = getID()
|
||||
_wsb = '/d/pipeline/workspaces'
|
||||
try:
|
||||
_wbr = await sor.sqlExe("SELECT params_value FROM params WHERE params_name='workspace_base' LIMIT 1", {})
|
||||
if _wbr and getattr(_wbr[0], 'params_value', ''):
|
||||
_wsb = getattr(_wbr[0], 'params_value', '')
|
||||
except Exception:
|
||||
pass
|
||||
_wsb = await get_workspace_base(sor)
|
||||
ws = _wsb + '/' + str(org_id) + '/' + name
|
||||
await sor.C('sd_projects',{'id':pid,'name':name,'description':p.get('description',''),'workspace_dir':ws,'org_id':org_id,'created_by':uid})
|
||||
await sor.C('sd_iterations',{'id':wid,'project_id':pid,'iteration_name':'默认迭代','iteration_type':'default','status':'active','priority':1,'org_id':org_id})
|
||||
|
||||
@ -8,31 +8,7 @@ dbname = get_module_dbname('pipeline-sdlc')
|
||||
import os
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
workspace_base = '/d/pipeline/workspaces'
|
||||
try:
|
||||
_wbr = await sor.sqlExe("SELECT params_value FROM params WHERE params_name='workspace_base' LIMIT 1", {})
|
||||
if _wbr and getattr(_wbr[0], 'params_value', ''):
|
||||
workspace_base = getattr(_wbr[0], 'params_value', '')
|
||||
except Exception:
|
||||
pass
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",
|
||||
{"u": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
|
||||
ws_dir = ''
|
||||
if pid:
|
||||
proj = await sor.sqlExe(
|
||||
"SELECT name, org_id, workspace_dir FROM sd_projects WHERE id=${p}$",
|
||||
{"p": pid})
|
||||
if proj:
|
||||
pname = getattr(proj[0], 'name', '')
|
||||
org_id = getattr(proj[0], 'org_id', '0') or '0'
|
||||
ws = getattr(proj[0], 'workspace_dir', '') or ''
|
||||
if ws and ws.startswith('/'):
|
||||
ws_dir = ws
|
||||
else:
|
||||
ws_dir = workspace_base + '/' + org_id + '/' + pname
|
||||
ws_dir, _ = await get_workspace_dir(sor, uid)
|
||||
|
||||
if not ws_dir or not os.path.isdir(ws_dir):
|
||||
return json.dumps({"error": "工作空间不存在: " + ws_dir, "tree": {"name": "", "children": [], "files": []}}, ensure_ascii=False)
|
||||
|
||||
@ -11,27 +11,7 @@ if not uid:
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
workspace_base = '/d/pipeline/workspaces'
|
||||
try:
|
||||
_wbr = await sor.sqlExe("SELECT params_value FROM params WHERE params_name='workspace_base' LIMIT 1", {})
|
||||
if _wbr and getattr(_wbr[0], 'params_value', ''):
|
||||
workspace_base = getattr(_wbr[0], 'params_value', '')
|
||||
except Exception:
|
||||
pass
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$", {"u": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
ws_dir = ''
|
||||
if pid:
|
||||
proj = await sor.sqlExe("SELECT name, org_id, workspace_dir FROM sd_projects WHERE id=${p}$", {"p": pid})
|
||||
if proj:
|
||||
ws = getattr(proj[0], 'workspace_dir', '') or ''
|
||||
if ws.startswith('/'):
|
||||
ws_dir = ws
|
||||
else:
|
||||
pname = getattr(proj[0], 'name', '')
|
||||
org_id = getattr(proj[0], 'org_id', '0') or '0'
|
||||
ws_dir = workspace_base + '/' + org_id + '/' + pname
|
||||
ws_dir, _ = await get_workspace_dir(sor, uid)
|
||||
|
||||
if not file_id or file_id == '__root__':
|
||||
return {"status": "error", "message": "不能删除根目录"}
|
||||
|
||||
@ -14,27 +14,7 @@ if not uid:
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
workspace_base = '/d/pipeline/workspaces'
|
||||
try:
|
||||
_wbr = await sor.sqlExe("SELECT params_value FROM params WHERE params_name='workspace_base' LIMIT 1", {})
|
||||
if _wbr and getattr(_wbr[0], 'params_value', ''):
|
||||
workspace_base = getattr(_wbr[0], 'params_value', '')
|
||||
except Exception:
|
||||
pass
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$", {"u": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
ws_dir = ''
|
||||
if pid:
|
||||
proj = await sor.sqlExe("SELECT name, org_id, workspace_dir FROM sd_projects WHERE id=${p}$", {"p": pid})
|
||||
if proj:
|
||||
ws = getattr(proj[0], 'workspace_dir', '') or ''
|
||||
if ws.startswith('/'):
|
||||
ws_dir = ws
|
||||
else:
|
||||
pname = getattr(proj[0], 'name', '')
|
||||
org_id = getattr(proj[0], 'org_id', '0') or '0'
|
||||
ws_dir = workspace_base + '/' + org_id + '/' + pname
|
||||
ws_dir, _ = await get_workspace_dir(sor, uid)
|
||||
|
||||
if not file_id or file_id == '__root__':
|
||||
return {"widgettype": "Message", "options": {"title": "错误", "message": "未指定文件"}}
|
||||
|
||||
@ -12,27 +12,7 @@ if not uid:
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
workspace_base = '/d/pipeline/workspaces'
|
||||
try:
|
||||
_wbr = await sor.sqlExe("SELECT params_value FROM params WHERE params_name='workspace_base' LIMIT 1", {})
|
||||
if _wbr and getattr(_wbr[0], 'params_value', ''):
|
||||
workspace_base = getattr(_wbr[0], 'params_value', '')
|
||||
except Exception:
|
||||
pass
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$", {"u": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
ws_dir = ''
|
||||
if pid:
|
||||
proj = await sor.sqlExe("SELECT name, org_id, workspace_dir FROM sd_projects WHERE id=${p}$", {"p": pid})
|
||||
if proj:
|
||||
ws = getattr(proj[0], 'workspace_dir', '') or ''
|
||||
if ws.startswith('/'):
|
||||
ws_dir = ws
|
||||
else:
|
||||
pname = getattr(proj[0], 'name', '')
|
||||
org_id = getattr(proj[0], 'org_id', '0') or '0'
|
||||
ws_dir = workspace_base + '/' + org_id + '/' + pname
|
||||
ws_dir, _ = await get_workspace_dir(sor, uid)
|
||||
|
||||
if not folder_id or folder_id == '__root__':
|
||||
full_dir = ws_dir
|
||||
|
||||
@ -13,27 +13,7 @@ if not uid:
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
workspace_base = '/d/pipeline/workspaces'
|
||||
try:
|
||||
_wbr = await sor.sqlExe("SELECT params_value FROM params WHERE params_name='workspace_base' LIMIT 1", {})
|
||||
if _wbr and getattr(_wbr[0], 'params_value', ''):
|
||||
workspace_base = getattr(_wbr[0], 'params_value', '')
|
||||
except Exception:
|
||||
pass
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$", {"u": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
ws_dir = ''
|
||||
if pid:
|
||||
proj = await sor.sqlExe("SELECT name, org_id, workspace_dir FROM sd_projects WHERE id=${p}$", {"p": pid})
|
||||
if proj:
|
||||
ws = getattr(proj[0], 'workspace_dir', '') or ''
|
||||
if ws.startswith('/'):
|
||||
ws_dir = ws
|
||||
else:
|
||||
pname = getattr(proj[0], 'name', '')
|
||||
org_id = getattr(proj[0], 'org_id', '0') or '0'
|
||||
ws_dir = workspace_base + '/' + org_id + '/' + pname
|
||||
ws_dir, _ = await get_workspace_dir(sor, uid)
|
||||
|
||||
if not file_id:
|
||||
return {"widgettype": "Message", "options": {"title": "打开失败", "message": "未指定文件"}}
|
||||
|
||||
@ -11,30 +11,7 @@ if not uid:
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
# workspace_base 从 appbase params 表读(可动态配置),默认值兜底
|
||||
workspace_base = '/d/pipeline/workspaces'
|
||||
try:
|
||||
_wbr = await sor.sqlExe(
|
||||
"SELECT params_value FROM params WHERE params_name='workspace_base' LIMIT 1", {})
|
||||
if _wbr and getattr(_wbr[0], 'params_value', ''):
|
||||
workspace_base = getattr(_wbr[0], 'params_value', '')
|
||||
except Exception:
|
||||
pass
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",
|
||||
{"u": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
|
||||
ws_dir = ''
|
||||
if pid:
|
||||
proj = await sor.sqlExe(
|
||||
"SELECT name, org_id, workspace_dir FROM sd_projects WHERE id=${p}$",
|
||||
{"p": pid})
|
||||
if proj:
|
||||
pname = getattr(proj[0], 'name', '')
|
||||
org_id = getattr(proj[0], 'org_id', '0') or '0'
|
||||
ws = getattr(proj[0], 'workspace_dir', '') or ''
|
||||
ws_dir = ws if ws.startswith('/') else workspace_base + '/' + org_id + '/' + pname
|
||||
ws_dir, _ = await get_workspace_dir(sor, uid)
|
||||
|
||||
if not ws_dir or not os.path.isdir(ws_dir):
|
||||
if not node_id:
|
||||
|
||||
@ -14,27 +14,7 @@ if not uid:
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
workspace_base = '/d/pipeline/workspaces'
|
||||
try:
|
||||
_wbr = await sor.sqlExe("SELECT params_value FROM params WHERE params_name='workspace_base' LIMIT 1", {})
|
||||
if _wbr and getattr(_wbr[0], 'params_value', ''):
|
||||
workspace_base = getattr(_wbr[0], 'params_value', '')
|
||||
except Exception:
|
||||
pass
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$", {"u": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
ws_dir = ''
|
||||
if pid:
|
||||
proj = await sor.sqlExe("SELECT name, org_id, workspace_dir FROM sd_projects WHERE id=${p}$", {"p": pid})
|
||||
if proj:
|
||||
ws = getattr(proj[0], 'workspace_dir', '') or ''
|
||||
if ws.startswith('/'):
|
||||
ws_dir = ws
|
||||
else:
|
||||
pname = getattr(proj[0], 'name', '')
|
||||
org_id = getattr(proj[0], 'org_id', '0') or '0'
|
||||
ws_dir = workspace_base + '/' + org_id + '/' + pname
|
||||
ws_dir, _ = await get_workspace_dir(sor, uid)
|
||||
|
||||
if not ws_dir or not os.path.isdir(ws_dir):
|
||||
return {"status": "error", "message": "工作空间目录不可用"}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user