# Support for scanning init scripts for LSB info
-import re, sys, os
-import pickle
+# Python3-compatible print() function
+from __future__ import print_function
-try:
- from io import StringIO
-except ImportError:
- from cStringIO import StringIO
+import re, sys, os, io
+import pickle
class RFC822Parser(dict):
"A dictionary-like object."
super(RFC822Parser, self).__init__(basedict)
if not fileob:
- fileob = StringIO(strob)
+ fileob = io.StringIO(strob)
key = None
for line in fileob:
if facility.startswith('$'): continue
for (scriptname, pri) in entries.items():
start, stop = pri
- print >> fh, "%(scriptname)s %(facility)s %(start)d %(stop)d" % locals()
+ print("%(scriptname)s %(facility)s %(start)d %(stop)d" % locals(), file=fh)
fh.close()
def load_facilities():
facilities.setdefault(name, {})[scriptname] = (int(start),
int(stop))
except ValueError as x:
- print >> sys.stderr, 'Invalid facility line', line
+ print('Invalid facility line', line, file=sys.stderr)
return facilities
fh = file(DEPENDS, 'w')
for initfile, facilities in depends.iteritems():
- print >> fh, '%s: %s' % (initfile, ' '.join(facilities))
+ print('%s: %s' % (initfile, ' '.join(facilities)), fh)
fh.close()
# filemap entries are mappings, { (package, filename) : instloc }
return {}
fh = open(LSBINSTALL, 'rb')
- filemap = cPickle.load(fh)
+ filemap = pickle.load(fh)
fh.close()
# Just in case it's corrupted somehow
return
fh = open(LSBINSTALL, 'wb')
- cPickle.dump(fh, filemap)
+ pickle.dump(fh, filemap)
fh.close()
if __name__ == '__main__':
- print (scan_initfile('init-fragment'))
+ print(scan_initfile('init-fragment'))