mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 14:26:07 +08:00
修复查询 python 依赖存在逻辑
This commit is contained in:
parent
eb1c00984c
commit
f94582b68d
|
@ -514,6 +514,20 @@ export async function setSystemTimezone(timezone: string): Promise<boolean> {
|
|||
}
|
||||
}
|
||||
|
||||
export function getGetCommand(type: DependenceTypes, name: string): string {
|
||||
const baseCommands = {
|
||||
[DependenceTypes.nodejs]: `pnpm ls -g | grep "${name}" | head -1`,
|
||||
[DependenceTypes.python3]: `python3 -c "import importlib;pkg=importlib.import_module('${name}');print(getattr(pkg, '__version__', 'version not found'))"`,
|
||||
[DependenceTypes.linux]: `apk info -es ${name}`,
|
||||
};
|
||||
|
||||
let command = baseCommands[type];
|
||||
|
||||
return type === DependenceTypes.python3
|
||||
? command
|
||||
: `${command} ${name.trim()}`;
|
||||
}
|
||||
|
||||
export function getInstallCommand(type: DependenceTypes, name: string): string {
|
||||
const baseCommands = {
|
||||
[DependenceTypes.nodejs]: 'pnpm add -g',
|
||||
|
|
|
@ -41,12 +41,6 @@ export enum DependenceTypes {
|
|||
'linux',
|
||||
}
|
||||
|
||||
export enum GetDependenceCommandTypes {
|
||||
'pnpm ls -g ',
|
||||
'pip3 show --disable-pip-version-check',
|
||||
'apk info -es',
|
||||
}
|
||||
|
||||
export enum versionDependenceCommandTypes {
|
||||
'@',
|
||||
'==',
|
||||
|
|
|
@ -6,7 +6,6 @@ import {
|
|||
DependenceStatus,
|
||||
DependenceTypes,
|
||||
DependenceModel,
|
||||
GetDependenceCommandTypes,
|
||||
versionDependenceCommandTypes,
|
||||
} from '../data/dependence';
|
||||
import { spawn } from 'cross-spawn';
|
||||
|
@ -19,6 +18,7 @@ import {
|
|||
promiseExecSuccess,
|
||||
getInstallCommand,
|
||||
getUninstallCommand,
|
||||
getGetCommand,
|
||||
} from '../config/util';
|
||||
import dayjs from 'dayjs';
|
||||
import taskLimit from '../shared/pLimit';
|
||||
|
@ -252,7 +252,7 @@ export default class DependenceService {
|
|||
|
||||
// 判断是否已经安装过依赖
|
||||
if (isInstall && !force) {
|
||||
const getCommandPrefix = GetDependenceCommandTypes[dependency.type];
|
||||
const getCommand = getGetCommand(dependency.type, depName);
|
||||
const depVersionStr = versionDependenceCommandTypes[dependency.type];
|
||||
let depVersion = '';
|
||||
if (depName.includes(depVersionStr)) {
|
||||
|
@ -269,13 +269,7 @@ export default class DependenceService {
|
|||
const isLinuxDependence = dependency.type === DependenceTypes.linux;
|
||||
const isPythonDependence =
|
||||
dependency.type === DependenceTypes.python3;
|
||||
const depInfo = (
|
||||
await promiseExecSuccess(
|
||||
isNodeDependence
|
||||
? `${getCommandPrefix} | grep "${depName}" | head -1`
|
||||
: `${getCommandPrefix} ${depName}`,
|
||||
)
|
||||
)
|
||||
const depInfo = (await promiseExecSuccess(getCommand))
|
||||
.replace(/\s{2,}/, ' ')
|
||||
.replace(/\s+$/, '');
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user