Skip to content

Commit c97bd5a

Browse files
committed
Update the python scripts to be python3-compatible
1 parent 37fde85 commit c97bd5a

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

scripts/mutate_files

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ while the majority of the installation process occurs as the unprivileged user.
3131
import os, pickle, sys
3232

3333
if len(sys.argv) != 2:
34-
print "This script is not intended to be called manually."
34+
print ("This script is not intended to be called manually.")
3535
exit(1)
3636

3737
installation_files = pickle.loads(sys.argv[1])
@@ -42,32 +42,32 @@ paths = set([os.path.dirname(filename) for filename in installation_files.keys()
4242
for path in paths:
4343
if os.path.exists(path):
4444
if not os.access(path, os.W_OK | os.X_OK):
45-
print "Unable to write to path: %s" % path
45+
print ("Unable to write to path: %s" % path)
4646
exit(1)
4747
else:
4848
try:
4949
os.makedirs(path)
5050
except:
51-
print "Unable to create path: %s" % path
51+
print ("Unable to create path: %s" % path)
5252

5353
# Mutate files according to the provided spec. We sort the list in reverse length
5454
# order so that when we are trying to remove a directory it is after everything in
5555
# it has already been removed.
56-
paths = installation_files.keys()
56+
paths = list(installation_files.keys())
5757
paths.sort(key=len, reverse=True)
5858
for path in paths:
5959
recipe = installation_files[path]
6060

6161
if 'symlink' in recipe:
6262
try:
6363
os.symlink(recipe['symlink'], path)
64-
except OSError, e:
64+
except OSError as e:
6565
# In case the symlink already exists, remove it before creating
6666
if e.errno == 17:
6767
os.unlink(path)
6868
os.symlink(recipe['symlink'], path)
6969
else:
70-
print "Unable to create symlink: %s" % path
70+
print ("Unable to create symlink: %s" % path)
7171

7272
if 'content' in recipe:
7373
with open(path, 'w') as f:
@@ -81,7 +81,7 @@ for path in paths:
8181
try:
8282
os.rmdir(path)
8383
except OSError:
84-
print "WARNING: Unable to remove directory %s. Additional user-added files may be present." % path
84+
print ("WARNING: Unable to remove directory %s. Additional user-added files may be present." % path)
8585
else:
8686
os.remove(path)
8787

src/robot_upstart/install_script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import robot_upstart
2929
from catkin.find_in_workspaces import find_in_workspaces
3030

31-
import providers
31+
from . import providers
3232

3333
DESC_PKGPATH = ("Make sure the path starts with the package name"
3434
" (e.g. don't pass absolute path nor a path starting from"
@@ -97,7 +97,7 @@ def main():
9797

9898
found_path = find_in_workspaces(project=pkg, path=pkgpath, first_match_only=True)
9999
if not found_path:
100-
print "Unable to locate path %s in package %s. Installation aborted." % (pkgpath, pkg)
100+
print ("Unable to locate path %s in package %s. Installation aborted." % (pkgpath, pkg))
101101
return 1
102102

103103
if os.path.isfile(found_path[0]):

src/robot_upstart/job.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from catkin.find_in_workspaces import find_in_workspaces
3535

36-
import providers
36+
from . import providers
3737

3838

3939
class Job(object):
@@ -163,7 +163,7 @@ def install(self, root="/", sudo="/usr/bin/sudo", Provider=None):
163163

164164
print "Preparing to install files to the following paths:"
165165
for filename in sorted(installation_files.keys()):
166-
print " %s" % filename
166+
print (" %s" % filename)
167167

168168
self._call_mutate(sudo, installation_files)
169169
p.post_install()
@@ -186,11 +186,11 @@ def uninstall(self, root="/", sudo="/usr/bin/sudo", Provider=None):
186186
installation_files = p.generate_uninstall()
187187

188188
if len(installation_files) == 0:
189-
print "Job not found, nothing to remove."
189+
print ("Job not found, nothing to remove.")
190190
else:
191191
print "Preparing to remove the following paths:"
192192
for filename in sorted(installation_files.keys()):
193-
print " %s" % filename
193+
print (" %s" % filename)
194194

195195
self._call_mutate(sudo, installation_files)
196196

@@ -208,13 +208,13 @@ def _call_mutate(self, sudo, installation_files):
208208
cmd = [mutate_files_exec]
209209
if sudo:
210210
cmd.insert(0, sudo)
211-
print "Now calling: %s" % ' '.join(cmd)
211+
print ("Now calling: %s" % ' '.join(cmd))
212212
p = subprocess.Popen(cmd + [pickle.dumps(installation_files)])
213213
p.communicate()
214214

215215
if p.returncode == 0:
216-
print "Filesystem operation succeeded."
216+
print ("Filesystem operation succeeded.")
217217
else:
218-
print "Error encountered; filesystem operation aborted."
218+
print ("Error encountered; filesystem operation aborted.")
219219

220220
return p.returncode

src/robot_upstart/providers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030

3131
import em
3232
import os
33-
import StringIO
33+
import io
3434

3535
from catkin.find_in_workspaces import find_in_workspaces
3636

3737

3838
def detect_provider():
3939
cmd = open('/proc/1/cmdline', 'rb').read().split('\x00')[0]
40-
print os.path.realpath(cmd)
40+
print (os.path.realpath(cmd))
4141
if 'systemd' in os.path.realpath(cmd):
4242
return Systemd
4343
return Upstart
@@ -116,7 +116,7 @@ def generate_install(self):
116116
# all of it. A more sophisticated future implementation could track contents or hashes and
117117
# thereby warn users when a new installation is stomping a change they have made.
118118
self._load_installed_files_set()
119-
self.installed_files_set.update(self.installation_files.keys())
119+
self.installed_files_set.update(list(self.installation_files.keys()))
120120

121121
# Remove the job directory. This will fail if it is not empty, and notify the user.
122122
self.installed_files_set.add(self.job.job_path)
@@ -146,7 +146,7 @@ def _set_job_path(self):
146146
self.root, "etc/ros", self.job.rosdistro, self.job.name + ".d")
147147

148148
def _fill_template(self, template):
149-
self.interpreter.output = StringIO.StringIO()
149+
self.interpreter.output = io.StringIO()
150150
self.interpreter.reset()
151151
with open(find_in_workspaces(project="robot_upstart", path=template)[0]) as f:
152152
self.interpreter.file(f)
@@ -191,7 +191,7 @@ def generate_install(self):
191191
# all of it. A more sophisticated future implementation could track contents or hashes and
192192
# thereby warn users when a new installation is stomping a change they have made.
193193
self._load_installed_files_set()
194-
self.installed_files_set.update(self.installation_files.keys())
194+
self.installed_files_set.update(list(self.installation_files.keys()))
195195

196196
# Remove the job directory. This will fail if it is not empty, and notify the user.
197197
self.installed_files_set.add(self.job.job_path)
@@ -223,7 +223,7 @@ def _set_job_path(self):
223223
self.root, "etc/ros", self.job.rosdistro, self.job.name + ".d")
224224

225225
def _fill_template(self, template):
226-
self.interpreter.output = StringIO.StringIO()
226+
self.interpreter.output = io.StringIO()
227227
self.interpreter.reset()
228228
with open(find_in_workspaces(project="robot_upstart", path=template)[0]) as f:
229229
self.interpreter.file(f)

0 commit comments

Comments
 (0)