itom
Loading...
Searching...
No Matches
pipManager.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2023, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************** */
22
23#ifndef PIPMANAGER_H
24#define PIPMANAGER_H
25
26#include <qabstractitemmodel.h>
27#include <qprocess.h>
28
29#include "../common/sharedStructures.h"
30
31namespace ito
32{
33
35{
36 enum Status {Unknown, Uptodate, Outdated};
37 PythonPackage() : m_status(Unknown), m_detailsFetched(false) {};
38 PythonPackage(const QString &name, const QString &version) :
39 m_name(name), m_version(version), m_location(""), m_requires(""), m_status(Unknown), m_newVersion(""), m_detailsFetched(false)
40 {}
41 QString m_name;
42 QString m_version;
43 QString m_location;
44 QString m_requires;
45 Status m_status;
46 QString m_newVersion;
47 QString m_summary;
48 QString m_homepage;
49 QString m_license;
50 bool m_detailsFetched;
51};
52
54{
55 PipGeneralOptions() : isolated(false), logPath(""), proxy(""), timeout(15), retries(5), useTrustedHosts(false) {}
56 bool isolated; //if true, --isolated is added to pip calls
57 QString logPath; //if != "" --log <logPath> is added to pip calls
58 QString proxy; //if != "" --proxy <proxy> is added to pip calls
59 int timeout; //if >= 0 --timeout <sec> is added to pip calls where timeout denotes the number of seconds
60 int retries; //if > 0 --retries <retries> is added to pip calls where retries denotes the number of tries if one command failed.
61 bool useTrustedHosts; //if true, each host in the corresponding text field (semicolon separated list) will be appended via --trusted-host to any pip command
62 QStringList trustedHosts; //trusted hosts, only considered if useTrustedHosts is true
63};
64
66{
67 enum Type
68 {
69 typeWhl = 0,
70 typeTarGz = 1,
71 typeSearchIndex = 2,
72 typeRequirements = 3,
73 typePackageSource = 4
74 }; //these are the same types than in DialogPipManager
75
76 Type type;
77 QString packageName;
78 bool upgrade;
79 bool installDeps;
80 QString findLinks;
81 bool ignoreIndex;
82 bool runAsSudo;
83};
84
85class PipManager : public QAbstractItemModel
86{
87 Q_OBJECT
88
89 public:
90 PipManager(ito::RetVal &retval, QObject *parent = 0);
92
93 enum Task {
94 taskNo,
95 taskCheckAvailable,
96 taskListPackages,
97 taskFetchPackagesDetails,
98 taskCheckUpdates,
99 taskInstall,
100 taskUninstall,
101 taskVerifyInstalledPackages
102 };
103
104 enum PipMode {
107
110 pipModeRunPipUtf8
111 };
112
113 QVariant data(const QModelIndex &index, int role) const;
114 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
115 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
116 QModelIndex parent(const QModelIndex &index) const;
117 int rowCount(const QModelIndex &parent = QModelIndex()) const;
118 int columnCount(const QModelIndex &parent = QModelIndex()) const;
119
120 void startPipProcess();
121 bool isPipStarted() const;
122 inline int getPipVersion() const { return m_pipVersion; }
123
124 void checkPipAvailable(const PipGeneralOptions &options = PipGeneralOptions());
125 void listAvailablePackages(const PipGeneralOptions &options = PipGeneralOptions(), bool forceReloadDetails = false);
126 void checkPackageUpdates(const PipGeneralOptions &options = PipGeneralOptions());
127 void checkVerifyInstalledPackages(const PipGeneralOptions &options = PipGeneralOptions());
128 void installPackage(const PipInstall &installSettings, const PipGeneralOptions &options = PipGeneralOptions());
129 void uninstallPackage(const QString &packageName, bool runAsSudo, const PipGeneralOptions &options = PipGeneralOptions());
130
131
132 void interruptPipProcess();
133
134 bool isPackageInUseByOther(const QModelIndex &index);
135
136
137 private:
138 QStringList parseGeneralOptions(const PipGeneralOptions &options, bool ignoreRetries = false, bool ignoreVersionCheck = true) const;
139 void clearBuffers();
140 ito::RetVal initPythonIfStandalone();
142 void startProcess(const QStringList &arguments);
143
144 QList<QString> m_headers;
145 QList<QVariant> m_alignment;
146 QList<PythonPackage> m_pythonPackages;
147 QProcess m_pipProcess;
148 bool m_pipAvailable;
149 QByteArray m_standardOutputBuffer;
150 QByteArray m_standardErrorBuffer;
151 Task m_currentTask;
152 PipGeneralOptions m_generalOptionsCache;
153 QString m_pythonPath;
154 int m_pipVersion; //form 0x060100 for 6.1.0
155 wchar_t *m_pUserDefinedPythonHome; //only used for standalone usage
156 PipMode m_pipCallMode;
158
159 int m_numberOfUnfetchedPackageDetails;
160 int m_numberOfNewlyObtainedPackageDetails;
161 bool m_fetchDetailCancelRequested;
162
163 void fetchPackageDetails(const QStringList& names, int totalNumberOfUnfetchedDetails, bool firstCall);
164 void updatePythonPackageDetails(const PythonPackage& details);
165 bool triggerFetchDetailsForOpenPackages(bool firstCall);
166
167 void finalizeTask(int exitCode = 0);
168 void finalizeTaskCheckAvailable(const QString& error, const QString& output, int exitCode);
169 void finalizeTaskListPackages(const QString& error, const QString& output);
170 void finalizeTaskFetchPackagesDetails(const QString& error, const QString& output);
171 void finalizeTaskCheckUpdates(const QString& error, const QString& output);
172 void finalizeTaskVerifyInstalledPackages(const QString& error, const QString& output);
173 void finalizeTaskInstall(const QString& error, const QString& output);
174 void finalizeTaskUninstall(const QString& error, const QString& output);
175
176 private slots:
177 void processError(QProcess::ProcessError error);
178 void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
179 void processReadyReadStandardError();
180 void processReadyReadStandardOutput();
181
182 signals:
183 void pipManagerBusy();
184 void outputAvailable(const QString &text, bool success);
185 void pipVersion(const QString &version);
186 void pipRequestStarted(const PipManager::Task &task, const QString &text, bool outputSilent = false);
187 void pipRequestFinished(const PipManager::Task &task, const QString &text, bool success);
188 void pipFetchDetailsProgress(int totalNumberOfUnfetchedDetails, int recentlyFetchedDetails, bool finished);
189};
190
191}
192
193#endif //PIPMANAGER_H
Definition pipManager.h:86
ito::RetVal checkCallMode()
check if pip can be called via the itom-packages/pipProcess/runPipUtf8.py script or directly
Definition pipManager.cpp:417
QList< QVariant > m_alignment
list of alignments for the corresponding headers
Definition pipManager.h:145
QList< QString > m_headers
string list of names of column headers
Definition pipManager.h:144
void startProcess(const QStringList &arguments)
the arguments string list must not contain -m as first entry.
Definition pipManager.cpp:584
QString m_runPipUtf8Path
only valid if m_pipCallMode == pipModeRunPipUtf8
Definition pipManager.h:157
PipManager(ito::RetVal &retval, QObject *parent=0)
Definition pipManager.cpp:44
~PipManager()
Definition pipManager.cpp:168
QVariant data(const QModelIndex &index, int role) const
Definition pipManager.cpp:493
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition pipManager.cpp:567
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition pipManager.cpp:462
QList< PythonPackage > m_pythonPackages
list with installed python packages
Definition pipManager.h:146
QModelIndex parent(const QModelIndex &index) const
Definition pipManager.cpp:452
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition pipManager.cpp:553
PipMode
Definition pipManager.h:104
@ pipModeDirect
directly call pip as process (might cause encoding errors under windows)
Definition pipManager.h:106
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition pipManager.cpp:471
Class for managing status values (like errors or warning)
Definition retVal.h:54
Definition apiFunctionsGraph.cpp:40
Definition pipManager.h:54
Definition pipManager.h:66
Definition pipManager.h:35