scipion-pyworkflow 3.10.6__py3-none-any.whl → 3.11.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. pyworkflow/config.py +131 -67
  2. pyworkflow/constants.py +2 -1
  3. pyworkflow/plugin.py +93 -44
  4. pyworkflow/resources/showj/arrowDown.png +0 -0
  5. pyworkflow/resources/showj/arrowUp.png +0 -0
  6. pyworkflow/resources/showj/background_section.png +0 -0
  7. pyworkflow/resources/showj/colRowModeOff.png +0 -0
  8. pyworkflow/resources/showj/colRowModeOn.png +0 -0
  9. pyworkflow/resources/showj/delete.png +0 -0
  10. pyworkflow/resources/showj/doc_icon.png +0 -0
  11. pyworkflow/resources/showj/download_icon.png +0 -0
  12. pyworkflow/resources/showj/enabled_gallery.png +0 -0
  13. pyworkflow/resources/showj/galleryViewOff.png +0 -0
  14. pyworkflow/resources/showj/galleryViewOn.png +0 -0
  15. pyworkflow/resources/showj/goto.png +0 -0
  16. pyworkflow/resources/showj/menu.png +0 -0
  17. pyworkflow/resources/showj/separator.png +0 -0
  18. pyworkflow/resources/showj/tableViewOff.png +0 -0
  19. pyworkflow/resources/showj/tableViewOn.png +0 -0
  20. pyworkflow/resources/showj/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  21. pyworkflow/resources/showj/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  22. pyworkflow/resources/showj/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  23. pyworkflow/resources/showj/volumeOff.png +0 -0
  24. pyworkflow/resources/showj/volumeOn.png +0 -0
  25. pyworkflow/viewer.py +23 -1
  26. pyworkflowtests/protocols.py +1 -3
  27. {scipion_pyworkflow-3.10.6.dist-info → scipion_pyworkflow-3.11.0.dist-info}/METADATA +13 -27
  28. scipion_pyworkflow-3.11.0.dist-info/RECORD +71 -0
  29. {scipion_pyworkflow-3.10.6.dist-info → scipion_pyworkflow-3.11.0.dist-info}/WHEEL +1 -1
  30. pyworkflow/apps/__init__.py +0 -29
  31. pyworkflow/apps/pw_manager.py +0 -37
  32. pyworkflow/apps/pw_plot.py +0 -51
  33. pyworkflow/apps/pw_project.py +0 -113
  34. pyworkflow/apps/pw_protocol_list.py +0 -143
  35. pyworkflow/apps/pw_protocol_run.py +0 -51
  36. pyworkflow/apps/pw_run_tests.py +0 -267
  37. pyworkflow/apps/pw_schedule_run.py +0 -322
  38. pyworkflow/apps/pw_sleep.py +0 -37
  39. pyworkflow/apps/pw_sync_data.py +0 -439
  40. pyworkflow/apps/pw_viewer.py +0 -78
  41. pyworkflow/gui/__init__.py +0 -36
  42. pyworkflow/gui/browser.py +0 -726
  43. pyworkflow/gui/canvas.py +0 -1190
  44. pyworkflow/gui/dialog.py +0 -977
  45. pyworkflow/gui/form.py +0 -2637
  46. pyworkflow/gui/graph.py +0 -247
  47. pyworkflow/gui/graph_layout.py +0 -271
  48. pyworkflow/gui/gui.py +0 -566
  49. pyworkflow/gui/matplotlib_image.py +0 -233
  50. pyworkflow/gui/plotter.py +0 -247
  51. pyworkflow/gui/project/__init__.py +0 -25
  52. pyworkflow/gui/project/base.py +0 -192
  53. pyworkflow/gui/project/constants.py +0 -139
  54. pyworkflow/gui/project/labels.py +0 -205
  55. pyworkflow/gui/project/project.py +0 -492
  56. pyworkflow/gui/project/searchprotocol.py +0 -154
  57. pyworkflow/gui/project/searchrun.py +0 -181
  58. pyworkflow/gui/project/steps.py +0 -171
  59. pyworkflow/gui/project/utils.py +0 -332
  60. pyworkflow/gui/project/variables.py +0 -179
  61. pyworkflow/gui/project/viewdata.py +0 -472
  62. pyworkflow/gui/project/viewprojects.py +0 -510
  63. pyworkflow/gui/project/viewprotocols.py +0 -2093
  64. pyworkflow/gui/project/viewprotocols_extra.py +0 -559
  65. pyworkflow/gui/text.py +0 -771
  66. pyworkflow/gui/tooltip.py +0 -185
  67. pyworkflow/gui/tree.py +0 -684
  68. pyworkflow/gui/widgets.py +0 -307
  69. pyworkflow/mapper/__init__.py +0 -26
  70. pyworkflow/mapper/mapper.py +0 -222
  71. pyworkflow/mapper/sqlite.py +0 -1581
  72. pyworkflow/mapper/sqlite_db.py +0 -145
  73. pyworkflow/project/__init__.py +0 -31
  74. pyworkflow/project/config.py +0 -454
  75. pyworkflow/project/manager.py +0 -180
  76. pyworkflow/project/project.py +0 -2007
  77. pyworkflow/protocol/__init__.py +0 -38
  78. pyworkflow/protocol/bibtex.py +0 -48
  79. pyworkflow/protocol/constants.py +0 -87
  80. pyworkflow/protocol/executor.py +0 -471
  81. pyworkflow/protocol/hosts.py +0 -314
  82. pyworkflow/protocol/launch.py +0 -270
  83. pyworkflow/protocol/package.py +0 -42
  84. pyworkflow/protocol/params.py +0 -741
  85. pyworkflow/protocol/protocol.py +0 -2641
  86. pyworkflow/tests/__init__.py +0 -29
  87. pyworkflow/tests/test_utils.py +0 -25
  88. pyworkflow/tests/tests.py +0 -341
  89. pyworkflow/utils/__init__.py +0 -38
  90. pyworkflow/utils/dataset.py +0 -414
  91. pyworkflow/utils/echo.py +0 -104
  92. pyworkflow/utils/graph.py +0 -169
  93. pyworkflow/utils/log.py +0 -284
  94. pyworkflow/utils/path.py +0 -528
  95. pyworkflow/utils/process.py +0 -153
  96. pyworkflow/utils/profiler.py +0 -92
  97. pyworkflow/utils/progressbar.py +0 -154
  98. pyworkflow/utils/properties.py +0 -631
  99. pyworkflow/utils/reflection.py +0 -129
  100. pyworkflow/utils/utils.py +0 -879
  101. pyworkflow/utils/which.py +0 -229
  102. pyworkflow/webservices/__init__.py +0 -8
  103. pyworkflow/webservices/config.py +0 -11
  104. pyworkflow/webservices/notifier.py +0 -162
  105. pyworkflow/webservices/repository.py +0 -59
  106. pyworkflow/webservices/workflowhub.py +0 -74
  107. pyworkflowtests/tests/__init__.py +0 -0
  108. pyworkflowtests/tests/test_canvas.py +0 -72
  109. pyworkflowtests/tests/test_domain.py +0 -45
  110. pyworkflowtests/tests/test_logs.py +0 -74
  111. pyworkflowtests/tests/test_mappers.py +0 -392
  112. pyworkflowtests/tests/test_object.py +0 -507
  113. pyworkflowtests/tests/test_project.py +0 -42
  114. pyworkflowtests/tests/test_protocol_execution.py +0 -142
  115. pyworkflowtests/tests/test_protocol_export.py +0 -78
  116. pyworkflowtests/tests/test_protocol_output.py +0 -158
  117. pyworkflowtests/tests/test_streaming.py +0 -47
  118. pyworkflowtests/tests/test_utils.py +0 -210
  119. scipion_pyworkflow-3.10.6.dist-info/RECORD +0 -140
  120. scipion_pyworkflow-3.10.6.dist-info/dependency_links.txt +0 -1
  121. {scipion_pyworkflow-3.10.6.dist-info → scipion_pyworkflow-3.11.0.dist-info}/entry_points.txt +0 -0
  122. {scipion_pyworkflow-3.10.6.dist-info → scipion_pyworkflow-3.11.0.dist-info}/licenses/LICENSE.txt +0 -0
  123. {scipion_pyworkflow-3.10.6.dist-info → scipion_pyworkflow-3.11.0.dist-info}/top_level.txt +0 -0
@@ -1,314 +0,0 @@
1
- # **************************************************************************
2
- # *
3
- # * Authors: J.M. De la Rosa Trevin (jmdelarosa@cnb.csic.es)
4
- # *
5
- # * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6
- # *
7
- # * This program is free software; you can redistribute it and/or modify
8
- # * it under the terms of the GNU General Public License as published by
9
- # * the Free Software Foundation; either version 3 of the License, or
10
- # * (at your option) any later version.
11
- # *
12
- # * This program is distributed in the hope that it will be useful,
13
- # * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # * GNU General Public License for more details.
16
- # *
17
- # * You should have received a copy of the GNU General Public License
18
- # * along with this program; if not, write to the Free Software
19
- # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20
- # * 02111-1307 USA
21
- # *
22
- # * All comments concerning this program package may be sent to the
23
- # * e-mail address 'scipion@cnb.csic.es'
24
- # *
25
- # **************************************************************************
26
- """
27
- This modules contains classes to store information about
28
- execution hosts.
29
- """
30
-
31
-
32
- import os
33
- import sys
34
- import json
35
- from configparser import RawConfigParser
36
- from collections import OrderedDict
37
-
38
- import pyworkflow as pw
39
- from pyworkflow import PARALLEL_COMMAND_VAR
40
- from pyworkflow.object import Object, String, Integer
41
-
42
-
43
- class HostConfig(Object):
44
- """ Main store the configuration for execution hosts. """
45
-
46
- def __init__(self, **kwargs):
47
- super().__init__(**kwargs)
48
- self.label = String(kwargs.get('label', None))
49
- self.hostName = String(kwargs.get('hostName', None))
50
- self.userName = String()
51
- self.password = String()
52
- self.hostPath = String()
53
- self.mpiCommand = String()
54
- self.scipionHome = String()
55
- self.scipionConfig = String()
56
- self.address = String()
57
- self.queueSystem = QueueSystemConfig()
58
-
59
- def getLabel(self):
60
- return self.label.get()
61
-
62
- def getHostName(self):
63
- return self.hostName.get()
64
-
65
- def getUserName(self):
66
- return self.userName.get()
67
-
68
- def getPassword(self):
69
- return self.password.get()
70
-
71
- def getHostPath(self):
72
- return self.hostPath.get()
73
-
74
- def getSubmitCommand(self):
75
- return self.queueSystem.submitCommand.get()
76
-
77
- def getSubmitPrefix(self):
78
- return self.queueSystem.submitPrefix.get()
79
-
80
- def getCheckCommand(self):
81
- return self.queueSystem.checkCommand.get()
82
-
83
- def getCancelCommand(self):
84
- return self.queueSystem.cancelCommand.get()
85
-
86
- def isQueueMandatory(self):
87
- return self.queueSystem.mandatory.get()
88
-
89
- def getSubmitTemplate(self):
90
- return self.queueSystem.getSubmitTemplate()
91
-
92
- def getQueuesDefault(self):
93
- return self.queueSystem.queuesDefault
94
-
95
- def getMpiCommand(self):
96
- return self.mpiCommand.get()
97
-
98
- def getQueueSystem(self):
99
- return self.queueSystem
100
-
101
- def getJobDoneRegex(self):
102
- return self.queueSystem.jobDoneRegex.get()
103
-
104
- def setLabel(self, label):
105
- self.label.set(label)
106
-
107
- def setHostName(self, hostName):
108
- self.hostName.set(hostName)
109
-
110
- def setUserName(self, userName):
111
- self.userName.set(userName)
112
-
113
- def setPassword(self, password):
114
- self.password.set(password)
115
-
116
- def setHostPath(self, hostPath):
117
- self.hostPath.set(hostPath)
118
-
119
- def setMpiCommand(self, mpiCommand):
120
- self.mpiCommand.set(mpiCommand)
121
-
122
- def setQueueSystem(self, queueSystem):
123
- self.queueSystem = queueSystem
124
-
125
- def getScipionHome(self):
126
- """ Return the path where Scipion is installed in
127
- the host.
128
- """
129
- return self.scipionHome.get()
130
-
131
- def setScipionHome(self, newScipionHome):
132
- self.scipionHome.set(newScipionHome)
133
-
134
- def getScipionConfig(self):
135
- """ From which file to read the configuration file in
136
- this hosts.
137
- """
138
- return self.scipionConfig.get()
139
-
140
- def setScipionConfig(self, newConfig):
141
- self.scipionConfig.set(newConfig)
142
-
143
- def getAddress(self):
144
- return self.address.get()
145
-
146
- def setAddress(self, newAddress):
147
- return self.address.set(newAddress)
148
-
149
- @classmethod
150
- def writeBasic(cls, configFn):
151
- """ Write a very basic Host configuration for testing purposes. """
152
- with open(configFn, 'w') as f:
153
- f.write('[localhost]\nPARALLEL_COMMAND = '
154
- 'mpirun -np %_(JOB_NODES)d --map-by node %_(COMMAND)s\n')
155
-
156
- @classmethod
157
- def load(cls, hostsConf):
158
- """ Load several hosts from a configuration file.
159
- Return an dictionary with hostName -> hostConfig pairs.
160
- """
161
- # Read from users' config file. Raw to avoid interpolation of %: we expect %_
162
- cp = RawConfigParser(comment_prefixes=";")
163
- cp.optionxform = str # keep case (stackoverflow.com/questions/1611799)
164
- hosts = OrderedDict()
165
-
166
- try:
167
- assert cp.read(hostsConf) != [], 'Missing file %s' % hostsConf
168
-
169
- for hostName in cp.sections():
170
- host = HostConfig(label=hostName, hostName=hostName)
171
- host.setHostPath(pw.Config.SCIPION_USER_DATA)
172
-
173
- # Helper functions (to write less)
174
- def get(var, default=None):
175
- if cp.has_option(hostName, var):
176
-
177
- value = cp.get(hostName, var)
178
- # Rescue python2.7 behaviour: ## at the beginning of a line, means a single #.
179
- # https://github.com/scipion-em/scipion-pyworkflow/issues/70
180
- value = value.replace("\n##", "\n#")
181
-
182
- # Keep compatibility: %_ --> %%
183
- value = value.replace('%_(', '%(')
184
-
185
- return value
186
- else:
187
- return default
188
-
189
- def getDict(var):
190
- od = OrderedDict()
191
-
192
- if cp.has_option(hostName, var):
193
- for key, value in json.loads(get(var)).items():
194
- od[key] = value
195
-
196
- return od
197
-
198
- host.setScipionHome(get(pw.SCIPION_HOME_VAR, pw.Config.SCIPION_HOME))
199
- host.setScipionConfig(pw.Config.SCIPION_CONFIG)
200
- # Read the address of the remote hosts,
201
- # using 'localhost' as default for backward compatibility
202
- host.setAddress(get('ADDRESS', 'localhost'))
203
- host.mpiCommand.set(get(PARALLEL_COMMAND_VAR))
204
- host.queueSystem = QueueSystemConfig()
205
- hostQueue = host.queueSystem # shortcut
206
- hostQueue.name.set(get('NAME'))
207
-
208
- # If the NAME is not provided or empty
209
- # do no try to parse the rest of Queue parameters
210
- if hostQueue.hasName():
211
- hostQueue.setMandatory(get('MANDATORY', 0))
212
- hostQueue.submitPrefix.set(get('SUBMIT_PREFIX', ''))
213
- hostQueue.submitCommand.set(get('SUBMIT_COMMAND'))
214
- hostQueue.submitTemplate.set(get('SUBMIT_TEMPLATE'))
215
- hostQueue.cancelCommand.set(get('CANCEL_COMMAND'))
216
- hostQueue.checkCommand.set(get('CHECK_COMMAND'))
217
- hostQueue.jobDoneRegex.set(get('JOB_DONE_REGEX'))
218
- hostQueue.queues = getDict('QUEUES')
219
- hostQueue.queuesDefault = getDict('QUEUES_DEFAULT')
220
-
221
- hosts[hostName] = host
222
-
223
- return hosts
224
- except Exception as e:
225
- sys.exit('Failed to read settings. The reported error was:\n %s\n'
226
- 'Review %s and run again.'
227
- % (e, os.path.abspath(hostsConf)))
228
-
229
-
230
- class QueueSystemConfig(Object):
231
- def __init__(self, **kwargs):
232
- super().__init__(**kwargs)
233
- self.name = String()
234
- # Number of cores from which the queue is mandatory
235
- # 0 means no mandatory at all
236
- # 1 will force to launch all jobs through the queue
237
- self.mandatory = Integer()
238
- self.queues = None # List for queue configurations
239
- self.submitCommand = String()
240
- # Allow to change the prefix of submission scripts
241
- # we used by default the ID.job, but in some clusters
242
- # the job script should start by a letter
243
- self.submitPrefix = String()
244
- self.checkCommand = String()
245
- self.cancelCommand = String()
246
- self.submitTemplate = String()
247
- self.jobDoneRegex = String()
248
-
249
- def hasName(self):
250
- return self.name.hasValue()
251
-
252
- def hasValue(self):
253
- return self.hasName() and len(self.queues)
254
-
255
- def getName(self):
256
- return self.name.get()
257
-
258
- def getMandatory(self):
259
- return self.mandatory.get()
260
-
261
- def getSubmitTemplate(self):
262
- return self.submitTemplate.get()
263
-
264
- def getSubmitCommand(self):
265
- return self.submitCommand.get()
266
-
267
- def getCheckCommand(self):
268
- return self.checkCommand.get()
269
-
270
- def getCancelCommand(self):
271
- return self.cancelCommand.get()
272
-
273
- def getQueues(self):
274
- return self.queues
275
-
276
- def setName(self, name):
277
- self.name.set(name)
278
-
279
- def setMandatory(self, mandatory):
280
- # This condition is to be backward compatible
281
- # when mandatory was a boolean
282
- # now it should use the number of CPU
283
- # that should force to use the queue
284
- if mandatory in ['False', 'false']:
285
- mandatory = 0
286
- elif mandatory in ['True', 'true']:
287
- mandatory = 1
288
-
289
- self.mandatory.set(mandatory)
290
-
291
- def setSubmitTemplate(self, submitTemplate):
292
- self.submitTemplate.set(submitTemplate)
293
-
294
- def setSubmitCommand(self, submitCommand):
295
- self.submitCommand.set(submitCommand)
296
-
297
- def setCheckCommand(self, checkCommand):
298
- self.checkCommand.set(checkCommand)
299
-
300
- def setCancelCommand(self, cancelCommand):
301
- self.cancelCommand.set(cancelCommand)
302
-
303
- def setJobDoneRegex(self, jobDoneRegex):
304
- self.jobDoneRegex.set(jobDoneRegex)
305
-
306
- def setQueues(self, queues):
307
- self.queues = queues
308
-
309
- def getQueueConfig(self, objId):
310
- if objId is not None and self.queues is not None:
311
- for queueConfig in self.queues:
312
- if objId == queueConfig.getObjId():
313
- return queueConfig
314
- return None
@@ -1,270 +0,0 @@
1
- # **************************************************************************
2
- # *
3
- # * Authors: J.M. De la Rosa Trevin (jmdelarosa@cnb.csic.es)
4
- # *
5
- # * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6
- # *
7
- # * This program is free software; you can redistribute it and/or modify
8
- # * it under the terms of the GNU General Public License as published by
9
- # * the Free Software Foundation; either version 3 of the License, or
10
- # * (at your option) any later version.
11
- # *
12
- # * This program is distributed in the hope that it will be useful,
13
- # * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # * GNU General Public License for more details.
16
- # *
17
- # * You should have received a copy of the GNU General Public License
18
- # * along with this program; if not, write to the Free Software
19
- # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20
- # * 02111-1307 USA
21
- # *
22
- # * All comments concerning this program package may be sent to the
23
- # * e-mail address 'scipion@cnb.csic.es'
24
- # *
25
- # **************************************************************************
26
- """
27
- This module is responsible for launching local protocol executions:
28
-
29
- 1- Check if the protocol will be submitted to a queue (using Queue template from config)
30
- 2- Build the command that will be launched.
31
-
32
- """
33
-
34
- import os
35
- import re
36
- import logging
37
- logger = logging.getLogger(__file__)
38
- from subprocess import Popen, PIPE
39
- import pyworkflow as pw
40
- from pyworkflow.exceptions import PyworkflowException
41
- from pyworkflow.utils import (redStr, greenStr, makeFilePath, join, process,
42
- getHostFullName)
43
- from pyworkflow.protocol.constants import UNKNOWN_JOBID, STATUS_FAILED, STATUS_FINISHED, STATUS_RUNNING
44
-
45
-
46
- # ******************************************************************
47
- # * Public functions provided by the module
48
- # ******************************************************************
49
-
50
- def launch(protocol, wait=False, stdin=None, stdout=None, stderr=None):
51
- """ This function should be used to launch a protocol. """
52
- _launchLocal(protocol, wait, stdin, stdout, stderr)
53
-
54
-
55
- def stop(protocol):
56
- """
57
- Stop function for three scenarios:
58
- - If the queue is not used, kill the main protocol process and its child processes.
59
- - If the queue is used and the entire protocol is sent to the queue, cancel the job running the protocol using
60
- scancel.
61
- - If the queue is used and individual steps are sent to the queue, cancel all active jobs and kill the main protocol
62
- process and its child processes.
63
- """
64
- if protocol.useQueue() and not protocol.isScheduled():
65
- jobIds = protocol.getJobIds()
66
- for jobId in jobIds: # Iter even though it contains only one jobId
67
- host = protocol.getHostConfig()
68
- cancelCmd = host.getCancelCommand() % {'JOB_ID': jobId}
69
- logger.info(cancelCmd)
70
- _run(cancelCmd, wait=True)
71
-
72
- if protocol.useQueueForSteps():
73
- process.killWithChilds(protocol.getPid())
74
- else:
75
- process.killWithChilds(protocol.getPid())
76
-
77
-
78
- def schedule(protocol, initialSleepTime=0, wait=False):
79
- """ Use this function to schedule protocols that are not ready to
80
- run yet. Right now it only make sense to schedule jobs locally.
81
- """
82
- cmd = '%s %s' % (pw.PYTHON, pw.getScheduleScript())
83
- cmd += ' "%s" "%s" %s "%s" --initial_sleep %s' % (protocol.getProject().path,
84
- protocol.getDbPath(),
85
- protocol.strId(),
86
- protocol.getScheduleLog(),
87
- initialSleepTime)
88
- pid = _run(cmd, wait)
89
- protocol.setPid(pid) # Set correctly the pid
90
-
91
-
92
- # ******************************************************************
93
- # * Internal utility functions
94
- # ******************************************************************
95
- def _runsLocally(protocol):
96
- """ Return True if this protocol is running in this machine,
97
- where the PID makes sense.
98
- """
99
- return protocol.getHostFullName() == getHostFullName()
100
-
101
-
102
- # ******************************************************************
103
- # * Function related to LAUNCH
104
- # ******************************************************************
105
- def _getAppsProgram(prog):
106
- """ Get a command to launch a program under the apps folder.
107
- """
108
- return "%s %s" % (pw.PYTHON, pw.join(pw.APPS, prog))
109
-
110
-
111
- def _launchLocal(protocol, wait, stdin=None, stdout=None, stderr=None):
112
- """
113
-
114
- :param protocol: Protocol to launch
115
- :param wait: Pass true if you want to wait for the process to finish
116
- :param stdin: stdin object to direct stdin to
117
- :param stdout: stdout object to send process stdout
118
- :param stderr: stderr object to send process stderr
119
- """
120
-
121
- command = '{python} {prot_run} "{project_path}" "{db_path}" {prot_id} "{stdout_log}" "{stderr_log}"'.format(
122
- python=pw.PYTHON,
123
- prot_run=pw.join(pw.APPS, 'pw_protocol_run.py'),
124
- project_path=protocol.getProject().path,
125
- db_path=protocol.getDbPath(),
126
- prot_id=protocol.strId(),
127
- # We make them absolute in case working dir is not passed to the node when running through a queue.
128
- # The reason is that since 3.0.27, the first thing that is affected by the current working dir is the
129
- # creation of the logs. Before event than loading the project, which was and is setting the working dir to
130
- # the project path. IMPORTANT: This assumes the paths before the queue and after the queue (nodes) are the same
131
- # Which I think is safe since we are passing here "project_path" that is absolute.
132
- stdout_log=os.path.abspath(protocol.getStdoutLog()),
133
- stderr_log=os.path.abspath(protocol.getStderrLog())
134
- )
135
-
136
- hostConfig = protocol.getHostConfig()
137
-
138
- # Clean Pid and JobIds
139
- protocol.cleanExecutionAttributes()
140
- protocol._store(protocol._jobId)
141
-
142
- # Handle three use cases: one will use the job ID, and the other two will use the process ID.
143
- if protocol.useQueueForProtocol(): # Retrieve the job ID and set it; this will be used to control the protocol.
144
- submitDict = dict(hostConfig.getQueuesDefault())
145
- submitDict.update(protocol.getSubmitDict())
146
- submitDict['JOB_COMMAND'] = command
147
- jobId = _submit(hostConfig, submitDict)
148
- if jobId is None or jobId == UNKNOWN_JOBID:
149
- protocol.setStatus(STATUS_FAILED)
150
- else:
151
- protocol.setJobId(jobId)
152
- protocol.setPid(0) # we go through the queue, so we rely on the jobId
153
- else: # If not, retrieve and set the process ID (both for normal execution or when using the queue for steps)
154
- pId = _run(command, wait, stdin, stdout, stderr)
155
- protocol.setPid(pId)
156
-
157
-
158
- def analyzeFormattingTypeError(string, dictionary):
159
- """ receives a string with %(VARS) to be replaced with a dictionary
160
- it splits te string by \n and test the formatting per line. Raises an exception if any line fails
161
- with all problems found"""
162
-
163
- # Do the replacement line by line
164
- lines = string.split("\n")
165
-
166
- problematicLines = []
167
- for line in lines:
168
- try:
169
- line % dictionary
170
- except KeyError as e:
171
- problematicLines.append(line + " --> variable not present in this context.")
172
- except Exception as e:
173
- problematicLines.append(line + " --> " + str(e))
174
-
175
- if problematicLines:
176
- return PyworkflowException('Following lines in %s seems to be problematic.\n'
177
- 'Values known in this context are: \n%s'
178
- 'Please review its format or content.\n%s' % (dictionary, pw.Config.SCIPION_HOSTS, "\n".join(problematicLines)),
179
- url=pw.DOCSITEURLS.HOST_CONFIG)
180
-
181
-
182
- def _submit(hostConfig, submitDict, cwd=None, env=None):
183
- """ Submit a protocol to a queue system. Return its job id.
184
- """
185
- # Create first the submission script to be launched
186
- # formatting using the template
187
- template = hostConfig.getSubmitTemplate()
188
-
189
- try:
190
- template = template % submitDict
191
- except Exception as e:
192
- # Capture parsing errors
193
- exception = analyzeFormattingTypeError(template, submitDict)
194
-
195
- if exception:
196
- raise exception
197
- else:
198
- # If there is no exception, then raise actual one
199
- raise e
200
-
201
- # FIXME: CREATE THE PATH FIRST
202
- scripPath = submitDict['JOB_SCRIPT']
203
- f = open(scripPath, 'w')
204
- # Ensure the path exists
205
- makeFilePath(scripPath)
206
- # Add some line ends because in some clusters it fails
207
- # to submit jobs if the submit script does not have end of line
208
- f.write(template + '\n\n')
209
- f.close()
210
- # This should format the command using a template like:
211
- # "qsub %(JOB_SCRIPT)s"
212
- command = hostConfig.getSubmitCommand() % submitDict
213
- gcmd = greenStr(command)
214
- logger.info("** Submitting to queue: '%s'" % gcmd)
215
-
216
- p = Popen(command, shell=True, stdout=PIPE, cwd=cwd, env=env)
217
- out = p.communicate()[0]
218
- # Try to parse the result of qsub, searching for a number (jobId)
219
- # Review this, seems to exclusive to torque batch system
220
- s = re.search(r'(\d+)', str(out))
221
- if p.returncode == 0 and s:
222
- job = int(s.group(0))
223
- logger.info("Launched job with id %s" % job)
224
- return job
225
- else:
226
- logger.info("Couldn't submit to queue for reason: %s " % redStr(out.decode()))
227
- return UNKNOWN_JOBID
228
-
229
- def _checkJobStatus(hostConfig, jobid):
230
- """
231
- General method to verify the job status in the queue based on the jobId and host.conf CHECK_COMMAND
232
- returns: STATUS_FINISHED (finished) or STATUS_RUNNING (running)
233
- """
234
- command = hostConfig.getCheckCommand() % {"JOB_ID": jobid}
235
- logger.debug("checking job status for %s: %s" % (jobid, command))
236
-
237
- p = Popen(command, shell=True, stdout=PIPE, preexec_fn=os.setsid)
238
-
239
- out = p.communicate()[0].decode(errors='backslashreplace')
240
-
241
- jobDoneRegex = hostConfig.getJobDoneRegex()
242
- logger.debug("Queue engine replied %s, variable JOB_DONE_REGEX has %s" % (out, jobDoneRegex))
243
- # If nothing is returned we assume job is no longer in queue and thus finished
244
- if out == "":
245
- logger.warning("Empty response from queue system to job (%s)" % jobid)
246
- return STATUS_FINISHED
247
-
248
- # If some string is returned we use the JOB_DONE_REGEX variable (if present) to infer the status
249
- elif jobDoneRegex is not None:
250
- s = re.search(jobDoneRegex, out)
251
- if s:
252
- logger.debug("Job (%s) finished" % jobid)
253
- return STATUS_FINISHED
254
- else:
255
- logger.debug("Job (%s) still running" % jobid)
256
- return STATUS_RUNNING
257
- # If JOB_DONE_REGEX is not defined and queue has returned something we assume that job is still running
258
- else:
259
- return STATUS_RUNNING
260
-
261
- def _run(command, wait, stdin=None, stdout=None, stderr=None):
262
- """ Execute a command in a subprocess and return the pid. """
263
- gcmd = greenStr(command)
264
- logger.info("** Running command: '%s'" % gcmd)
265
- p = Popen(command, shell=True, stdout=stdout, stderr=stderr)
266
- pid = p.pid
267
- if wait:
268
- p.wait()
269
-
270
- return pid
@@ -1,42 +0,0 @@
1
- # **************************************************************************
2
- # *
3
- # * Authors: P. Conesa Mingo (pconesa@cnb.csic.es)
4
- # *
5
- # * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6
- # *
7
- # * This program is free software; you can redistribute it and/or modify
8
- # * it under the terms of the GNU General Public License as published by
9
- # * the Free Software Foundation; either version 3 of the License, or
10
- # * (at your option) any later version.
11
- # *
12
- # * This program is distributed in the hope that it will be useful,
13
- # * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # * GNU General Public License for more details.
16
- # *
17
- # * You should have received a copy of the GNU General Public License
18
- # * along with this program; if not, write to the Free Software
19
- # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20
- # * 02111-1307 USA
21
- # *
22
- # * All comments concerning this program package may be sent to the
23
- # * e-mail address 'scipion@cnb.csic.es'
24
- # *
25
- # **************************************************************************
26
-
27
-
28
- """
29
- This modules contains classes related to EM package management
30
- """
31
-
32
-
33
- class Package:
34
- def __init__(self, name, installed):
35
- self._name = name
36
- self._installed = installed
37
-
38
- def isInstalled(self):
39
- return self._installed
40
-
41
- def getName(self):
42
- return self._name