install.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """
4 usage: %(progname)s robot robot_type web_user
5 """
6 
7 import os, sys, string, time, getopt
8 import pwd
9 import subprocess
10 
11 def make_file(fn, default):
12  if os.path.exists(fn): return
13 
14  open(fn, "w").write(default)
15 
16 def install(robot, robot_type, web_user):
17  config_dir = "/etc/ros/"
18  var_dir = "/var/ros/"
19  log_dir = "/var/log/ros/"
20 
21  user = pwd.getpwnam(web_user)
22  for path in (config_dir, var_dir, log_dir):
23  if not os.path.exists(path):
24  os.mkdir(path, 0755)
25  os.chown(path, user.pw_uid, user.pw_gid)
26 
27  make_file(os.path.join(config_dir, "user"), web_user)
28  make_file(os.path.join(config_dir, "master"), "http://localhost:11311/")
29  make_file(os.path.join(config_dir, "robot"), robot)
30  make_file(os.path.join(config_dir, "robot_type"), robot_type)
31 
32  subprocess.call(["install", "setup.bash", os.path.join(config_dir, "setup.bash")])
33  subprocess.call(["install", "apache.cfg", os.path.join(config_dir, "ros_webui_apache.cfg")])
34 
35  subprocess.call(["install", "webui.init", "/usr/bin/webui"])
36 
37 def test():
38  pass
39 
40 def usage(progname):
41  print __doc__ % vars()
42 
43 def main(argv, stdout, environ):
44  progname = argv[0]
45  optlist, args = getopt.getopt(argv[1:], "", ["help", "test", "debug"])
46 
47  testflag = 0
48 
49  if len(args) == 0:
50  usage(progname)
51  return
52 
53  for (field, val) in optlist:
54  if field == "--help":
55  usage(progname)
56  return
57  elif field == "--debug":
58  debugfull()
59  elif field == "--test":
60  testflag = 1
61 
62  if testflag:
63  test()
64  return
65 
66  robot = args[0]
67  robot_type = args[1]
68  web_user = args[2]
69 
70  install(robot, robot_type, web_user)
71 
72 
73 if __name__ == "__main__":
74  main(sys.argv, sys.stdout, os.environ)
def main(argv, stdout, environ)
Definition: install.py:43
def make_file(fn, default)
Definition: install.py:11
def usage(progname)
Definition: install.py:40
def install(robot, robot_type, web_user)
Definition: install.py:16
def test()
Definition: install.py:37


webui
Author(s): Scott Hassan
autogenerated on Mon Jun 10 2019 15:51:24