1
2
3
4
5
6 """
7 ls plugin
8 =========
9
10 This simply lists the files on disk. It is useful for testing the
11 plugin architecture.
12
13
14 Plugin class
15 ------------
16
17 .. autoclass:: Ls
18 :members: worker_class
19 :undoc-members:
20
21 Worker class
22 ------------
23
24 The worker class performs the analysis.
25
26 .. autoclass:: _Ls
27 :members:
28
29
30 """
31 from __future__ import with_statement
32
33 __docformat__ = "restructuredtext en"
34
35 import os.path
36 import warnings
37
38 import gromacs
39 from gromacs.utilities import AttributeDict
40 from gromacs.analysis.core import Worker, Plugin
41
42 import logging
43 logger = logging.getLogger('gromacs.analysis.plugins.ls')
44
45
46
47
48
49 -class _Ls(Worker):
50 """ls worker class."""
51
53 """
54 :Arguments:
55 *kwargs*
56 same as ls ??
57 """
58
59
60 super(_Ls, self).__init__(**kwargs)
61
62
63
64
65
66
67
68
69
70
71 if not self.simulation is None:
72 self._register_hook()
73
75 """Run when registering; requires simulation."""
76
77 super(_Ls, self)._register_hook(**kwargs)
78 assert not self.simulation is None
79
80
81
82
83 - def run(self, *args, **kwargs):
84 """List the contents of the simulation directory.
85 """
86
87 from subprocess import call
88 lscmd = ['ls', '-la'] + list(args)
89 cmd = lscmd + [self.simulation.tpr, self.simulation.xtc]
90 with rulify("TPR and XTC"):
91 rc = call(cmd)
92
93 adir = self.simulation.analysis_dir
94 cmd = lscmd + [adir]
95 with rulify("Analysis dir %(adir)s" % vars()):
96 rc = call(cmd)
97
100
101 - def plot(self, **kwargs):
103
104 from contextlib import contextmanager
105
106 @contextmanager
107 -def rulify(header, ncol=79):
108 toprule = ncol * '='
109 midrule = ncol * '-'
110 botrule = toprule
111 print toprule
112 print header
113 print midrule
114 try:
115 yield None
116 finally:
117 print botrule
118 print
119
120
121
122
123 -class Ls(Plugin):
124 """*ls* plugin.
125
126 This simply lists the files on disk. It is useful for testing the
127 plugin architecture.
128
129 .. class:: Ls([name[, simulation]])
130
131 :Arguments:
132 *name* : string
133 plugin name (used to access it)
134 *simulation* : instance
135 The :class:`gromacs.analysis.Simulation` instance that owns the plugin.
136
137 """
138 worker_class = _Ls
139