File: example7a.py

package info (click to toggle)
pyutilib 6.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,924 kB
  • sloc: python: 18,448; xml: 135; perl: 75; makefile: 50; sh: 32
file content (40 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pyutilib.workflow
import os.path
import os
currdir = os.path.dirname(os.path.abspath(__file__))+os.sep

import sys
if sys.platform.startswith('win'):
    INPUT = open('example7a.txt','r')
    for line in INPUT:
        sys.stdout.write(line)
    INPUT.close()
else:

# @ex:
  class TaskH(pyutilib.workflow.Task):

    def __init__(self, *args, **kwds):
        """Constructor."""
        pyutilib.workflow.Task.__init__(self, *args, **kwds)
        self.inputs.declare('dir')
        self.outputs.declare('list')
        self.add_resource(pyutilib.workflow.ExecutableResource(executable='/bin/ls'))

    def execute(self):
        self.resource('ls').run(self.dir, logfile=currdir+'logfile', debug=True)
        self.list = []
        INPUT = open(currdir+'logfile','r')
        for line in INPUT:
            self.list.append( line.strip() )
        INPUT.close()
        self.list.sort()

  H = TaskH()
  w = pyutilib.workflow.Workflow()
  w.add(H)
  print(w(dir=currdir+'dummy'))
# @:ex

  if os.path.exists(currdir+'logfile'):
    os.remove(currdir+'logfile')