installing python libs over dashboard

main
alex 2023-08-18 09:34:51 +00:00
parent 065296935e
commit c6bf7f85a9
8 changed files with 313 additions and 207 deletions

View File

@ -1,5 +1,4 @@
matplotlib==3.7.2
numpy==1.24.3
numpy_stl==3.0.1
Pillow==9.5.0
Pillow==10.0.0

View File

@ -1,37 +0,0 @@
Brlapi==0.8.2
certifi==2020.6.20
chardet==4.0.0
chrome-gnome-shell==0.0.0
cupshelpers==1.0
dbus-python==1.2.16
distlib==0.3.6
distro==1.5.0
distro-info==1.0
filelock==3.10.7
httplib2==0.18.1
idna==2.10
louis==3.16.0
numpy==1.24.3
numpy-stl==3.0.1
Pillow==9.5.0
platformdirs==3.2.0
pycairo==1.16.2
pycups==2.0.1
pycurl==7.43.0.6
PyGObject==3.38.0
PySimpleSOAP==1.16.2
pysmbc==1.0.23
python-apt==2.2.1
python-debian==0.1.39
python-debianbts==3.1.0
python-utils==3.6.0
pyxdg==0.27
reportbug==7.10.3+deb11u1
requests==2.25.1
six==1.16.0
typing_extensions==4.6.3
unattended-upgrades==0.1
urllib3==1.26.5
vboxapi==1.0
virtualenv==20.21.0
xdg==5

View File

View File

@ -128,5 +128,44 @@
"message": "System hat Schritt %step% von %groupTaskId% gestartet"
}
]
},
{
"id": 10,
"languages": [
{
"lang": "en",
"message": "%userId% has requested installing python packages for %groupId% of %category%"
},
{
"lang": "de",
"message": "%userId% hat die Installation der Python Pakete für %groupId% von %category% angefordert"
}
]
},
{
"id": 11,
"languages": [
{
"lang": "en",
"message": "Installing python packages for %groupId% of %category% failed. Error: %error%"
},
{
"lang": "de",
"message": "Installation der Python Pakete für %groupId% von %category% fehlgeschlagen. Fehler: %error%"
}
]
},
{
"id": 12,
"languages": [
{
"lang": "en",
"message": "Installing python packages for %groupId% of %category% finished. Log: %log%"
},
{
"lang": "de",
"message": "Installation der Python Pakete für %groupId% von %category% abgeschlossen. Log: %log%"
}
]
}
]

View File

@ -931,3 +931,92 @@ func StartGroupTask(userId string, groupTask structs.GroupTasks) {
},
})
}
func InstallPythonDependencies(userId string, category, groupId string) {
logger.AddGroupTasksLog(structs.LogMessage{
Id: 10,
Type: utils.LogTypeInfo,
Messages: []structs.LogData{
{Type: "userId", Value: userId},
{Type: "category", Value: category},
{Type: "groupId", Value: groupId},
},
})
messageBody := struct {
Category string
GroupId string
}{
Category: category,
GroupId: groupId,
}
socketclients.BroadcastMessageToUsersWithPermission(
systempermissions.ConvertXYPermission(utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, category),
structs.SendSocketMessage{
Cmd: utils.SentCmdInstallingPythonDependencies,
Body: messageBody,
})
// check if requirements.txt exists
if _, err := os.Stat(config.Cfg.FolderPaths.GroupTasksGroups + groupId + "/requirements.txt"); errors.Is(err, os.ErrNotExist) {
logger.AddGroupTasksLog(structs.LogMessage{
Id: 11,
Type: utils.LogTypeInfo,
Messages: []structs.LogData{
{Type: "category", Value: category},
{Type: "groupId", Value: groupId},
{Type: "error", Value: "requirements.txt not found"},
},
})
socketclients.BroadcastMessageToUsersWithPermission(
systempermissions.ConvertXYPermission(utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, category),
structs.SendSocketMessage{
Cmd: utils.SentCmdInstallingPythonDependenciesFailed,
Body: messageBody,
})
return
}
// install python dependencies
cmd := exec.Command("pip3", "install", "-r", config.Cfg.FolderPaths.GroupTasksGroups+groupId+"/requirements.txt")
out, err := cmd.CombinedOutput()
if err != nil {
logger.AddGroupTasksLog(structs.LogMessage{
Id: 11,
Type: utils.LogTypeInfo,
Messages: []structs.LogData{
{Type: "category", Value: category},
{Type: "groupId", Value: groupId},
{Type: "error", Value: err.Error()},
},
})
socketclients.BroadcastMessageToUsersWithPermission(
systempermissions.ConvertXYPermission(utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, category),
structs.SendSocketMessage{
Cmd: utils.SentCmdInstallingPythonDependenciesFailed,
Body: messageBody,
})
return
}
logger.AddGroupTasksLog(structs.LogMessage{
Id: 12,
Type: utils.LogTypeInfo,
Messages: []structs.LogData{
{Type: "category", Value: category},
{Type: "groupId", Value: groupId},
{Type: "log", Value: string(out)},
},
})
socketclients.BroadcastMessageToUsersWithPermission(
systempermissions.ConvertXYPermission(utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, category),
structs.SendSocketMessage{
Cmd: utils.SentCmdInstallingPythonDependenciesFinished,
Body: messageBody,
})
}

View File

@ -73,6 +73,9 @@ const (
SentCmdNewUserApiKeyCreated = 30
SentCmdDeletedUserApiKey = 31
SentCmdNewApiKeyUsageCount = 32
SentCmdInstallingPythonDependencies = 33
SentCmdInstallingPythonDependenciesFailed = 34
SentCmdInstallingPythonDependenciesFinished = 35
)
// commands received from web clients
@ -97,6 +100,7 @@ const (
ReceivedCmdHandleUserActionTaskStep = 18
ReceivedCmdCreateNewUserApiKey = 19
ReceivedCmdDeleteUserApiKey = 20
ReceivedCmdGroupTasksInstallPythonDependencies = 21
)
const (
@ -129,6 +133,7 @@ const (
_groupTasks = "group_tasks."
PermissionGroupTasksOverviewXYNewTask = _groupTasks + "overview.XY.new_task"
PermissionGroupTasksOverviewXYReloadGroupConfig = _groupTasks + "overview.XY.reload_group_config"
PermissionGroupTasksOverviewXYInstallPythonDependencies = _groupTasks + "overview.XY.install_python_dependencies"
PermissionGroupTasksOverviewXYView = _groupTasks + "overview.XY.view"
PermissionGroupTasksHistory = _groupTasks + "history"
PermissionGroupTasksCheckingForCategoryGroupChanges = _groupTasks + "checking_for_category_group_changes"
@ -169,5 +174,6 @@ var SystemPermissions = []string{
var DynamicGroupTasksPermissions = []string{
PermissionGroupTasksOverviewXYNewTask,
PermissionGroupTasksOverviewXYReloadGroupConfig,
PermissionGroupTasksOverviewXYInstallPythonDependencies,
PermissionGroupTasksOverviewXYView,
}

View File

@ -397,6 +397,14 @@ func RunHub() {
case utils.ReceivedCmdDeleteUserApiKey:
socketclients.DeleteUserApiKey(data.Conn.Locals("userId").(string), receivedMessage.Body["Id"].(string))
break
case utils.ReceivedCmdGroupTasksInstallPythonDependencies:
if !socketclients.HasXYPermission(data.Conn.Locals("userId").(string), utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, receivedMessage.Body["category"].(string)) {
socketclients.SendErrorMessageNoPermissions(data.Conn.Locals("sessionId").(string))
break
}
grouptasks.InstallPythonDependencies(data.Conn.Locals("userId").(string), receivedMessage.Body["category"].(string), receivedMessage.Body["groupId"].(string))
break
default:
log.Error().Msgf("Received unknown message: %v", receivedMessage)

2
start.sh Executable file
View File

@ -0,0 +1,2 @@
screen -dmS admin-dashboard-backend | exit 0
screen -S admin-dashboard-backend -p 0 -X stuff 'go run main.go\n'