File: manager.py

package info (click to toggle)
mmtk 2.7.9-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,788 kB
  • ctags: 6,600
  • sloc: python: 18,050; ansic: 12,400; makefile: 129; csh: 3
file content (69 lines) | stat: -rw-r--r-- 1,867 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Command script for managing trajectory files in a networked environment.
# Requires that a TrajectoryServer is running on each participating machine.
#
# Written by Konrad Hinsen
#

import Pyro.core, Pyro.naming, Pyro.errors
from TrajectoryManager import TrajectoryManager
import os, socket, string, sys

manager = TrajectoryManager()

def show_usage():
    sys.stderr.write('Usage: tmanager command [arguments]\n')
    sys.stderr.write('  Commands:\n')
    sys.stderr.write('     list\n')
    sys.stderr.write('     status\n')
    sys.stderr.write('     publish filename\n')
    sys.stderr.write('     unpublish filename\n')
    sys.stderr.write('     servers\n')
    sys.stderr.write('     shutdown\n')
    sys.exit(1)

def list_trajectories():
    files = manager.trajectoryList()
    for file in files:
        sys.stdout.write(file+'\n')
        sys.stdout.flush()

def trajectory_status():
    files = manager.trajectoryList()
    for file in files:
        inspector = manager.trajectoryInspector(file)
        inspector.reopen()
        sys.stdout.write('%s\n    %d steps\n' %
                         (file, inspector.numberOfSteps()))
        sys.stdout.flush()

def list_servers():
    servers = manager.serverList()
    for server in servers:
        sys.stdout.write(server+'\n')
        sys.stdout.flush()

def quit():
    manager = find_manager()
    if manager is None:
        return
    manager.stop()

commands = {'list': list_trajectories,
            'status': trajectory_status,
            'publish': manager.publish,
            'unpublish': manager.unpublish,
            'servers': list_servers,
            'shutdown': manager.stopServer}

if len(sys.argv) < 2:
    show_usage()

try:
    function = commands[sys.argv[1]]
except KeyError:
    show_usage()

try:
    apply(function, tuple(sys.argv[2:]))
except TypeError:
    show_usage()