OpendTect-6_4  6.4
pythonaccess.h
Go to the documentation of this file.
1 #ifndef pythonaccess_h
2 #define pythonaccess_h
3 
4 /*
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A. Huck
9  Date: May 2019
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 */
14 
15 #include "basicmod.h"
16 
17 #include "bufstring.h"
18 #include "callback.h"
19 #include "enums.h"
20 
21 class FilePath;
22 class Timer;
23 class uiPythonSettings;
24 class uiString;
25 
26 namespace OS {
27  class CommandExecPars;
28  class CommandLauncher;
29  class MachineCommand;
30 }
31 
32 
33 namespace OD
34 {
36  {
38  };
40 
43  public:
44  PythonAccess();
45  ~PythonAccess();
46 
47  uiRetVal isUsable(bool force=false,
48  const char* scriptstr=nullptr,
49  const char* scriptexpectedout=nullptr) const;
50 
51  bool execute(const OS::MachineCommand&,
52  bool wait4finish=true) const;
53  bool execute(const OS::MachineCommand&,
54  BufferString& stdoutstr,
55  BufferString* stderrstr,
56  uiString* errmsg=nullptr) const;
57  bool execute(const OS::MachineCommand&,
58  const OS::CommandExecPars&,
59  int* pid=nullptr,
60  uiString* errmsg=nullptr) const;
61 
62  BufferString lastOutput(bool stderrout,uiString* launchermsg) const;
63  BufferString pyVersion() const;
64  uiString pySummary() const;
65 
66  bool isModuleUsable(const char* nm) const;
67 
68  static bool hasInternalEnvironment(bool allowuserdef=true);
69  static bool validInternalEnvironment(const FilePath&);
70 
71  static const char* sPythonExecNm(bool v3=false,bool v2=false);
72  static const char* sKeyPythonSrc();
73  static const char* sKeyEnviron();
74 
76 
77  mStruct(Basic) ModuleInfo : NamedObject
78  {
79  public:
80  ModuleInfo(const char*);
81 
82  BufferString displayStr(bool withver=true) const;
83 
84  BufferString versionstr_;
85  };
86 
87  uiRetVal verifyEnvironment(const char* piname);
88  BufferString getPacmanExecNm() const;
89  uiRetVal updateModuleInfo(const char* cmd="pip list");
90  /*<! Pass nullptr to auto-detect */
91  uiRetVal hasModule(const char* modname,
92  const char* minversion=0) const;
94 
95  private:
96 
97  bool istested_ = false;
98  bool isusable_ = false;
99  FilePath* activatefp_ = nullptr;
104  mutable uiString msg_;
107 
108  bool isUsable(bool force=false,
109  const char* scriptstr=nullptr,
110  const char* scriptexpectedout=nullptr);
111  static bool getInternalEnvironmentLocation(FilePath&,
112  bool userdef);
113  static FilePath getInternalEnvPath(bool userdef);
114  static bool getSortedVirtualEnvironmentLoc(
116  BufferStringSet& envnms,
117  const BufferString* envnm=nullptr,
118  const FilePath* extroot=nullptr);
119  bool isEnvUsable(const FilePath* pythonenvfp,
120  const char* envnm,
121  const char* scriptstr,
122  const char* scriptexpectedout);
123  static FilePath* getCommand(OS::MachineCommand&,
124  bool background,
125  const FilePath* activatefp,
126  const char* envnm);
127  static OS::CommandLauncher* getLauncher(const OS::MachineCommand&,
128  bool background,
129  const FilePath* activatefp,
130  const char* envnm,
131  FilePath& scriptfp);
132  static void getPIDFromFile(const char* pidfnm,int* pid);
133  bool doExecute(const OS::MachineCommand&,
134  const OS::CommandExecPars*,int* pid,
135  const FilePath* activatefp,
136  const char* envnm) const;
137  static FilePath* getActivateScript(const FilePath& root);
138  bool retrievePythonVersionStr();
139  void envChangeCB(CallBacker*);
140 
141  friend class ::uiPythonSettings;
142 
143  };
144 
145  mGlobal(Basic) PythonAccess& PythA();
146 
147  mGlobal(Basic) bool canDoCUDA(BufferString& maxverstr);
148 
149 } //namespace OD
150 
151 
152 #endif
153 
#define mExpClass(module)
Definition: commondefs.h:160
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
PythonSource
Definition: pythonaccess.h:35
Notifier< PythonAccess > envChange
Definition: pythonaccess.h:75
Definition: pythonaccess.h:37
BufferString laststdout_
Definition: pythonaccess.h:102
#define mStruct(module)
Definition: commondefs.h:165
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
Specifies how to execute a command.
Definition: oscommand.h:34
#define mGlobal(module)
Definition: commondefs.h:163
#define mDeclareNameSpaceEnumUtils(mod, enm)
Definition: enums.h:274
Definition: oscommand.h:24
Encapsulates an actual command to execute + the machine to run it on.
Definition: oscommand.h:80
Launches machine commands.
Definition: oscommand.h:143
Definition: uistring.h:89
Set of BufferString objects.
Definition: bufstringset.h:28
BufferString pythversion_
Definition: pythonaccess.h:105
Definition: pythonaccess.h:37
BufferString laststderr_
Definition: pythonaccess.h:103
Definition: callback.h:254
Set of pointers to objects.
Definition: commontypes.h:32
bool canDoCUDA(BufferString &maxverstr)
ManagedObjectSet< ModuleInfo > moduleinfos_
Definition: pythonaccess.h:106
PythonAccess & PythA()
PtrMan< OS::CommandLauncher > cl_
Definition: pythonaccess.h:101
File pathname tools.
Definition: filepath.h:34
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
Object with a name.
Definition: namedobj.h:35
Definition: uistring.h:243
Definition: pythonaccess.h:41
OpendTect.
Definition: commontypes.h:29
Timer class.
Definition: timer.h:25
BufferString virtenvnm_
Definition: pythonaccess.h:100
uiString msg_
Definition: pythonaccess.h:104
Definition: pythonaccess.h:37

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019