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