itom  3.0.0
pipManager.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet 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 
31 namespace ito
32 {
33 
35 {
36  enum Status {Unknown, Uptodate, Outdated};
37  PythonPackage() : m_status(Unknown) {};
38  PythonPackage(const QString &name, const QString &version, const QString &location, const QString &requires) :
39  m_name(name), m_version(version), m_location(location), m_requires(requires), m_status(Unknown), m_newVersion("")
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 };
51 
53 {
54  PipGeneralOptions() : isolated(false), logPath(""), proxy(""), timeout(15), retries(5) {}
55  bool isolated; //if true, --isolated is added to pip calls
56  QString logPath; //if != "" --log <logPath> is added to pip calls
57  QString proxy; //if != "" --proxy <proxy> is added to pip calls
58  int timeout; //if >= 0 --timeout <sec> is added to pip calls where timeout denotes the number of seconds
59  int retries; //if > 0 --retries <retries> is added to pip calls where retries denotes the number of tries if one command failed.
60 };
61 
62 struct PipInstall
63 {
64  enum Type { typeWhl = 0, typeTarGz = 1, typeSearchIndex = 2}; //these are the same types than in DialogPipManager
65  Type type;
66  QString packageName;
67  bool upgrade;
68  bool installDeps;
69  QString findLinks;
70  bool ignoreIndex;
71  bool runAsSudo;
72 };
73 
74 class PipManager : public QAbstractItemModel
75 {
76  Q_OBJECT
77 
78  public:
79  PipManager(ito::RetVal &retval, QObject *parent = 0);
80  ~PipManager();
81 
82  enum Task {taskNo, taskCheckAvailable, taskListPackages1, taskListPackages2, taskCheckUpdates, taskInstall, taskUninstall};
83 
84  QVariant data(const QModelIndex &index, int role) const;
85  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
86  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
87  QModelIndex parent(const QModelIndex &index) const;
88  int rowCount(const QModelIndex &parent = QModelIndex()) const;
89  int columnCount(const QModelIndex &parent = QModelIndex()) const;
90 
91  void startPipProcess();
92  bool isPipStarted() const;
93  inline int getPipVersion() const { return m_pipVersion; }
94 
95  void checkPipAvailable(const PipGeneralOptions &options = PipGeneralOptions());
96  void listAvailablePackages(const PipGeneralOptions &options = PipGeneralOptions());
97  void listAvailablePackages2(const QStringList &names);
98  void checkPackageUpdates(const PipGeneralOptions &options = PipGeneralOptions());
99  void installPackage(const PipInstall &installSettings, const PipGeneralOptions &options = PipGeneralOptions());
100  void uninstallPackage(const QString &packageName, bool runAsSudo, const PipGeneralOptions &options = PipGeneralOptions());
101  void finalizeTask(int exitCode = 0);
102 
103  void interruptPipProcess();
104 
105  bool isPackageInUseByOther(const QModelIndex &index);
106 
107 
108  private:
109  QStringList parseGeneralOptions(const PipGeneralOptions &options, bool ignoreRetries = false, bool ignoreVersionCheck = true) const;
110  void clearBuffers();
111  ito::RetVal initPythonIfStandalone();
112 
113  QList<QString> m_headers;
114  QList<QVariant> m_alignment;
115  QList<PythonPackage> m_pythonPackages;
116  QProcess m_pipProcess;
117  bool m_pipAvailable;
118  QByteArray m_standardOutputBuffer;
119  QByteArray m_standardErrorBuffer;
120  Task m_currentTask;
121  PipGeneralOptions m_generalOptionsCache;
122  QString m_pythonPath;
123  int m_pipVersion; //form 0x060100 for 6.1.0
124  wchar_t *m_pUserDefinedPythonHome; //only used for standalone usage
125 
126  private slots:
127  void processError(QProcess::ProcessError error);
128  void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
129  void processReadyReadStandardError();
130  void processReadyReadStandardOutput();
131 
132  signals:
133  void pipManagerBusy();
134  void outputAvailable(const QString &text, bool success);
135  void pipVersion(const QString &version);
136  void pipRequestStarted(const PipManager::Task &task, const QString &text, bool outputSilent = false);
137  void pipRequestFinished(const PipManager::Task &task, const QString &text, bool success);
138 };
139 
140 }
141 
142 #endif //PIPMANAGER_H
Class for managing status values (like errors or warning)
Definition: retVal.h:54
Definition: pipManager.h:62
Definition: apiFunctionsGraph.cpp:39
Definition: pipManager.h:52
QList< PythonPackage > m_pythonPackages
list with installed python packages
Definition: pipManager.h:115
Definition: pipManager.h:34
QList< QString > m_headers
string list of names of column headers
Definition: pipManager.h:113
Definition: pipManager.h:74
QList< QVariant > m_alignment
list of alignments for the corresponding headers
Definition: pipManager.h:114