summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-02-20 21:56:47 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-02-20 21:56:47 +0000
commitabc364013de96b1ff0170b65665388ed8ca3e07f (patch)
tree04e1b5c369edc905fea4e785cbbadc207a670571
parent202a3aec707802a85bbf5bfbf82e86a0317c2bbb (diff)
downloadbcfg2-abc364013de96b1ff0170b65665388ed8ca3e07f.tar.gz
bcfg2-abc364013de96b1ff0170b65665388ed8ca3e07f.tar.bz2
bcfg2-abc364013de96b1ff0170b65665388ed8ca3e07f.zip
os.popen is deprecated in 2.6 (http://docs.python.org/library/os.html#os.popen)
Signed-off-by: Sol Jerome <solj@ices.utexas.edu> git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5088 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--src/lib/Server/Admin/Init.py19
-rw-r--r--src/lib/Server/Admin/Viz.py36
-rw-r--r--src/lib/Server/Plugins/Git.py6
-rw-r--r--src/lib/Server/Plugins/SSHbase.py8
-rw-r--r--src/lib/Server/Plugins/Svn.py6
5 files changed, 47 insertions, 28 deletions
diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py
index 8f31b5cf1..af307ec4e 100644
--- a/src/lib/Server/Admin/Init.py
+++ b/src/lib/Server/Admin/Init.py
@@ -1,4 +1,9 @@
-import getpass, os, random, socket, string
+import getpass
+import os
+import random
+import socket
+import string
+import subprocess
import Bcfg2.Server.Admin
import Bcfg2.Options
@@ -130,7 +135,8 @@ class Init(Bcfg2.Server.Admin.Mode):
newpasswd = newpasswd + random.choice(chars)
return newpasswd
- def initializeRepo(self, configfile, repo, server_uri, password, os_selection, opts):
+ def initializeRepo(self, configfile, repo, server_uri,
+ password, os_selection, opts):
'''Setup a new repo'''
keypath = os.path.dirname(os.path.abspath(configfile))
@@ -149,7 +155,10 @@ class Init(Bcfg2.Server.Admin.Mode):
# FIXME automate ssl key generation
# FIXME key generation may fail as non-root user
- os.popen('openssl req -x509 -nodes -days 1000 -newkey rsa:1024 -out %s/bcfg2.key -keyout %s/bcfg2.key' % (keypath, keypath))
+ subprocess.call(("openssl " \
+ "req -x509 -nodes -days 1000 -newkey rsa:1024 " \
+ "-out %s/bcfg2.key -keyout %s/bcfg2.key" % \
+ (keypath, keypath)), shell=True)
try:
os.chmod('%s/bcfg2.key'% keypath, 0600)
except:
@@ -161,8 +170,8 @@ class Init(Bcfg2.Server.Admin.Mode):
return
else:
# FIXME repo creation may fail as non-root user
- for subdir in ['SSHbase', 'Cfg', 'Pkgmgr', 'Rules', 'etc', 'Metadata',
- 'Base', 'Bundler']:
+ for subdir in ['SSHbase', 'Cfg', 'Pkgmgr', 'Rules',
+ 'etc', 'Metadata', 'Base', 'Bundler']:
path = "%s/%s" % (repo, subdir)
newpath = ''
for subdir in path.split('/'):
diff --git a/src/lib/Server/Admin/Viz.py b/src/lib/Server/Admin/Viz.py
index 0a5a8b9d6..f973e90c5 100644
--- a/src/lib/Server/Admin/Viz.py
+++ b/src/lib/Server/Admin/Viz.py
@@ -1,4 +1,5 @@
-import getopt, popen2
+import getopt
+from subprocess import Popen, PIPE
import Bcfg2.Server.Admin
class Viz(Bcfg2.Server.Admin.MetadataCore):
@@ -71,25 +72,26 @@ class Viz(Bcfg2.Server.Admin.MetadataCore):
cmd = "dot -Tpng"
if output:
cmd += " -o %s" % output
- dotpipe = popen2.Popen4(cmd)
+ dotpipe = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE, close_fds=True)
try:
- dotpipe.tochild.write("digraph groups {\n")
+ dotpipe.stdin.write("digraph groups {\n")
except:
print "write to dot process failed. Is graphviz installed?"
raise SystemExit(1)
- dotpipe.tochild.write('\trankdir="LR";\n')
- dotpipe.tochild.write(self.metadata.viz(hosts, bundles,
+ dotpipe.stdin.write('\trankdir="LR";\n')
+ dotpipe.stdin.write(self.metadata.viz(hosts, bundles,
key, self.colors))
if key:
- dotpipe.tochild.write("\tsubgraph cluster_key {\n")
- dotpipe.tochild.write('''\tstyle="filled";\n''')
- dotpipe.tochild.write('''\tcolor="lightblue";\n''')
- dotpipe.tochild.write('''\tBundle [ shape="septagon" ];\n''')
- dotpipe.tochild.write('''\tGroup [shape="ellipse"];\n''')
- dotpipe.tochild.write('''\tProfile [style="bold", shape="ellipse"];\n''')
- dotpipe.tochild.write('''\tHblock [label="Host1|Host2|Host3", shape="record"];\n''')
- dotpipe.tochild.write('''\tlabel="Key";\n''')
- dotpipe.tochild.write("\t}\n")
- dotpipe.tochild.write("}\n")
- dotpipe.tochild.close()
- return dotpipe.fromchild.read()
+ dotpipe.stdin.write("\tsubgraph cluster_key {\n")
+ dotpipe.stdin.write('''\tstyle="filled";\n''')
+ dotpipe.stdin.write('''\tcolor="lightblue";\n''')
+ dotpipe.stdin.write('''\tBundle [ shape="septagon" ];\n''')
+ dotpipe.stdin.write('''\tGroup [shape="ellipse"];\n''')
+ dotpipe.stdin.write('''\tProfile [style="bold", shape="ellipse"];\n''')
+ dotpipe.stdin.write('''\tHblock [label="Host1|Host2|Host3", shape="record"];\n''')
+ dotpipe.stdin.write('''\tlabel="Key";\n''')
+ dotpipe.stdin.write("\t}\n")
+ dotpipe.stdin.write("}\n")
+ dotpipe.stdin.close()
+ return dotpipe.stdout.read()
diff --git a/src/lib/Server/Plugins/Git.py b/src/lib/Server/Plugins/Git.py
index 1c17c8e47..6cb089de6 100644
--- a/src/lib/Server/Plugins/Git.py
+++ b/src/lib/Server/Plugins/Git.py
@@ -1,4 +1,5 @@
import os
+from subprocess import Popen, PIPE
import Bcfg2.Server.Plugin
# for debugging output only
@@ -31,8 +32,9 @@ class Git(Bcfg2.Server.Plugin.Plugin,
def get_revision(self):
'''Read git revision information for the bcfg2 repository'''
try:
- data = os.popen("env LC_ALL=C git ls-remote %s" %
- (self.datastore)).readlines()
+ data = Popen(("env LC_ALL=C git ls-remote %s" %
+ (self.datastore)), shell=True,
+ stdout=PIPE).stdout.readlines()
revline = [line.split('\t')[0].strip() for line in data if \
line.split('\t')[1].strip() == 'refs/heads/master'][-1]
revision = revline
diff --git a/src/lib/Server/Plugins/SSHbase.py b/src/lib/Server/Plugins/SSHbase.py
index 4ca2fdf51..1485df626 100644
--- a/src/lib/Server/Plugins/SSHbase.py
+++ b/src/lib/Server/Plugins/SSHbase.py
@@ -1,7 +1,11 @@
'''This module manages ssh key files for bcfg2'''
__revision__ = '$Revision$'
-import binascii, os, socket, tempfile
+import binascii
+import os
+import socket
+import tempfile
+from subprocess import Popen, PIPE
import Bcfg2.Server.Plugin
class SSHbase(Bcfg2.Server.Plugin.Plugin,
@@ -128,7 +132,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin,
return (ipaddr, client)
except socket.gaierror:
cmd = "getent hosts %s" % client
- ipaddr = os.popen(cmd).read().strip().split()
+ ipaddr = Popen(cmd, shell=True, stdout=PIPE).stdout.read().strip().split()
if ipaddr:
self.ipcache[client] = (ipaddr, client)
return (ipaddr, client)
diff --git a/src/lib/Server/Plugins/Svn.py b/src/lib/Server/Plugins/Svn.py
index 269c3173b..2cdbecb99 100644
--- a/src/lib/Server/Plugins/Svn.py
+++ b/src/lib/Server/Plugins/Svn.py
@@ -1,4 +1,5 @@
import os
+from subprocess import Popen, PIPE
import Bcfg2.Server.Plugin
# for debugging output only
@@ -31,8 +32,9 @@ class Svn(Bcfg2.Server.Plugin.Plugin,
def get_revision(self):
'''Read svn revision information for the bcfg2 repository'''
try:
- data = os.popen("env LC_ALL=C svn info %s" \
- % (self.datastore)).readlines()
+ data = Popen(("env LC_ALL=C svn info %s" %
+ (self.datastore)), shell=True,
+ stdout=PIPE).stdout.readlines()
revline = [line.split(': ')[1].strip() for line in data \
if line[:9] == 'Revision:'][-1]
revision = revline