diff options
author | Bohuslav Kabrda <bkabrda@redhat.com> | 2014-12-12 11:04:40 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-01-13 10:25:37 +0100 |
commit | 341a00311680a440d7f979f06c34c70d86c9367a (patch) | |
tree | 95fdcbed6ddffb50958174c42157ceecaa06ac66 /src/config | |
parent | faae3d55e5cf416f16158d3b9f8c8fd475ac6acf (diff) | |
download | sssd-341a00311680a440d7f979f06c34c70d86c9367a.tar.gz sssd-341a00311680a440d7f979f06c34c70d86c9367a.tar.xz sssd-341a00311680a440d7f979f06c34c70d86c9367a.zip |
Python3 support in SSSD
https://fedorahosted.org/sssd/ticket/2017
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/SSSDConfig/ipachangeconf.py | 33 | ||||
-rw-r--r-- | src/config/SSSDConfig/sssd_upgrade_config.py | 33 | ||||
-rwxr-xr-x | src/config/SSSDConfigTest.py | 8 |
3 files changed, 38 insertions, 36 deletions
diff --git a/src/config/SSSDConfig/ipachangeconf.py b/src/config/SSSDConfig/ipachangeconf.py index 49394f20e..257c0f46d 100644 --- a/src/config/SSSDConfig/ipachangeconf.py +++ b/src/config/SSSDConfig/ipachangeconf.py @@ -34,7 +34,8 @@ def openLocked(filename, perms, create = True): try: fd = os.open(filename, flags, perms) fcntl.lockf(fd, fcntl.LOCK_EX) - except OSError, (errno, strerr): + except OSError as err: + errno, strerr = err.args if fd != -1: try: os.close(fd) @@ -73,7 +74,7 @@ class IPAChangeConf: elif type(indent) is str: self.indent = (indent, ) else: - raise ValueError, 'Indent must be a list of strings' + raise ValueError('Indent must be a list of strings') def setOptionAssignment(self, assign): if type(assign) is tuple: @@ -174,7 +175,7 @@ class IPAChangeConf: if o['type'] == "empty": output += self.deol continue - raise SyntaxError, 'Unknown type: ['+o['type']+']' + raise SyntaxError('Unknown type: ['+o['type']+']') return output @@ -189,7 +190,7 @@ class IPAChangeConf: parts = line.split(self.dassign, 1) if len(parts) < 2: - raise SyntaxError, 'Syntax Error: Unknown line format' + raise SyntaxError('Syntax Error: Unknown line format') return {'name':parts[0].strip(), 'type':'option', 'value':parts[1].rstrip()} @@ -238,7 +239,7 @@ class IPAChangeConf: if o['type'] == 'empty': opts.append({'name':'comment', 'type':'comment', 'value':''}) continue - raise SyntaxError, 'Unknown type: ['+o['type']+']' + raise SyntaxError('Unknown type: ['+o['type']+']') return opts @@ -263,7 +264,7 @@ class IPAChangeConf: continue if no['action'] == "remove": continue - raise SyntaxError, 'Unknown action: ['+no['action']+']' + raise SyntaxError('Unknown action: ['+no['action']+']') if o['type'] == "comment" or o['type'] == "empty": opts.append(o) @@ -285,9 +286,9 @@ class IPAChangeConf: if no['action'] == 'set': opts.append(no) continue - raise SyntaxError, 'Unknown action: ['+o['action']+']' + raise SyntaxError('Unknown action: ['+o['action']+']') - raise SyntaxError, 'Unknown type: ['+o['type']+']' + raise SyntaxError('Unknown type: ['+o['type']+']') return opts @@ -323,7 +324,7 @@ class IPAChangeConf: cline += 1 continue - raise SyntaxError, 'Unknown type: ['+no['type']+']' + raise SyntaxError('Unknown type: ['+no['type']+']') def merge(self, oldopts, newopts): @@ -368,7 +369,7 @@ class IPAChangeConf: value = self.matchSubSection(line) if value: if subsection is not None: - raise SyntaxError, 'nested subsections are not supported yet' + raise SyntaxError('nested subsections are not supported yet') subsectopts = [] curopts = subsectopts subsection = value @@ -377,7 +378,7 @@ class IPAChangeConf: value = self.matchSubSectionEnd(line) if value: if subsection is None: - raise SyntaxError, 'Unmatched end subsection terminator found' + raise SyntaxError('Unmatched end subsection terminator found') fatheropts.append({'name':subsection, 'type':'subsection', 'value':subsectopts}) subsection = None curopts = fatheropts @@ -407,7 +408,7 @@ class IPAChangeConf: #Do not catch an unexisting file error, we want to fail in that case shutil.copy2(file, file+self.backup_suffix) - f = openLocked(file, 0644) + f = openLocked(file, 0o644) oldopts = self.parse(f) @@ -441,12 +442,12 @@ class IPAChangeConf: try: try: shutil.copy2(file, file+self.backup_suffix) - except IOError, err: + except IOError as err: if err.errno == 2: # The orign file did not exist pass - f = openLocked(file, 0644) + f = openLocked(file, 0o644) # Trunkate f.seek(0) @@ -494,12 +495,12 @@ class SSSDChangeConf(IPAChangeConf): mo = self.OPTCRE.match(line) if not mo: - raise SyntaxError, 'Syntax Error: Unknown line format' + raise SyntaxError('Syntax Error: Unknown line format') try: name, value = mo.group('option', 'value') except IndexError: - raise SyntaxError, 'Syntax Error: Unknown line format' + raise SyntaxError('Syntax Error: Unknown line format') return {'name':name.strip(), 'type':'option', 'value':value.strip()} diff --git a/src/config/SSSDConfig/sssd_upgrade_config.py b/src/config/SSSDConfig/sssd_upgrade_config.py index 33d9fed74..282d6c46f 100644 --- a/src/config/SSSDConfig/sssd_upgrade_config.py +++ b/src/config/SSSDConfig/sssd_upgrade_config.py @@ -18,6 +18,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from __future__ import print_function import os import sys @@ -25,15 +26,15 @@ import shutil import traceback from optparse import OptionParser -from ipachangeconf import openLocked -from ipachangeconf import SSSDChangeConf +from .ipachangeconf import openLocked +from .ipachangeconf import SSSDChangeConf class SSSDConfigFile(SSSDChangeConf): def __init__(self, filename): SSSDChangeConf.__init__(self) self.filename = filename - f = openLocked(self.filename, 0600, False) + f = openLocked(self.filename, 0o600, False) self.opts = self.parse(f) f.close() @@ -41,7 +42,7 @@ class SSSDConfigFile(SSSDChangeConf): " Copy the file we operate on to a backup location " shutil.copy(file_name, file_name + self.backup_suffix) # make sure we don't leak data, force permissions on the backup - os.chmod(file_name + self.backup_suffix, 0600) + os.chmod(file_name + self.backup_suffix, 0o600) def get_version(self): ver = self.get_option_index('sssd', 'config_file_version')[1] @@ -50,7 +51,7 @@ class SSSDConfigFile(SSSDChangeConf): try: return int(ver['value']) except ValueError: - raise SyntaxError, 'config_file_version not an integer' + raise SyntaxError('config_file_version not an integer') def rename_opts(self, parent_name, rename_kw, type='option'): for new_name, old_name in rename_kw.items(): @@ -332,7 +333,7 @@ class SSSDConfigFile(SSSDChangeConf): of.write(output) of.close() # make sure it has the right permissions too - os.chmod(out_file_name, 0600) + os.chmod(out_file_name, 0o600) def upgrade_v2(self, out_file_name, backup=True): # read in the old file, make backup if needed @@ -352,7 +353,7 @@ class SSSDConfigFile(SSSDChangeConf): of.write(output) of.close() # make sure it has the right permissions too - os.chmod(out_file_name, 0600) + os.chmod(out_file_name, 0o600) def parse_options(): parser = OptionParser() @@ -383,7 +384,7 @@ by default""") def verbose(msg, verbose): if verbose: - print msg + print(msg) def main(): options = parse_options() @@ -397,33 +398,33 @@ def main(): verbose(traceback.format_exc(), options.verbose) print >>sys.stderr, "Cannot parse config file %s" % options.filename return 1 - except Exception, e: - print "ERROR: %s" % e + except Exception as e: + print("ERROR: %s" % e) verbose(traceback.format_exc(), options.verbose) return 1 # make sure we keep strict settings when creating new files - os.umask(0077) + os.umask(0o077) version = config.get_version() if version == 2: verbose("Looks like v2, only checking changes", options.verbose) try: config.v2_changes(options.outfile, options.backup) - except Exception, e: - print "ERROR: %s" % e + except Exception as e: + print("ERROR: %s" % e) verbose(traceback.format_exc(), options.verbose) return 1 elif version == 1: verbose("Looks like v1, performing full upgrade", options.verbose) try: config.upgrade_v2(options.outfile, options.backup) - except Exception, e: - print "ERROR: %s" % e + except Exception as e: + print("ERROR: %s" % e) verbose(traceback.format_exc(), options.verbose) return 1 else: - print >>sys.stderr, "Can only upgrade from v1 to v2, file %s looks like version %d" % (options.filename, config.get_version()) + print("Can only upgrade from v1 to v2, file %s looks like version %d" % (options.filename, config.get_version()), file=sys.stderr) return 1 return 0 diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py index 78e22f6ef..bdca8517d 100755 --- a/src/config/SSSDConfigTest.py +++ b/src/config/SSSDConfigTest.py @@ -148,7 +148,7 @@ class SSSDConfigTestValid(unittest.TestCase): #Output files should not be readable or writable by #non-owners, and should not be executable by anyone - self.assertFalse(S_IMODE(mode) & 0177) + self.assertFalse(S_IMODE(mode) & 0o177) #Remove the output file os.unlink(of) @@ -182,7 +182,7 @@ class SSSDConfigTestValid(unittest.TestCase): #Output files should not be readable or writable by #non-owners, and should not be executable by anyone - self.assertFalse(S_IMODE(mode) & 0177) + self.assertFalse(S_IMODE(mode) & 0o177) #Remove the output file os.unlink(of) @@ -216,7 +216,7 @@ class SSSDConfigTestValid(unittest.TestCase): #Output files should not be readable or writable by #non-owners, and should not be executable by anyone - self.assertFalse(S_IMODE(mode) & 0177) + self.assertFalse(S_IMODE(mode) & 0o177) #Remove the output file os.unlink(of) @@ -1767,7 +1767,7 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase): #Output files should not be readable or writable by #non-owners, and should not be executable by anyone - self.assertFalse(S_IMODE(mode) & 0177) + self.assertFalse(S_IMODE(mode) & 0o177) #Remove the output file os.unlink(of) |