diff options
author | Daniel Harding <dharding@gmail.com> | 2012-03-08 13:10:55 +0000 |
---|---|---|
committer | Daniel Harding <dharding@gmail.com> | 2012-03-08 13:10:55 +0000 |
commit | 3d10f1522f66ec841d770f9126e737b21f9b9973 (patch) | |
tree | b6179e10142ba786b4d70afb444a503b542f8693 | |
parent | 58da9a469d4553dad6c617b730d0bdff032e793b (diff) | |
download | dotfiles-3d10f1522f66ec841d770f9126e737b21f9b9973.tar.gz dotfiles-3d10f1522f66ec841d770f9126e737b21f9b9973.tar.bz2 dotfiles-3d10f1522f66ec841d770f9126e737b21f9b9973.zip |
Make source compatible with Python 3
Replaced a few Python 2-only idioms with equivalents that work in both Python 2
and Python 3.
-rw-r--r-- | dotfiles/core.py | 18 | ||||
-rwxr-xr-x | test_dotfiles.py | 2 |
2 files changed, 11 insertions, 9 deletions
diff --git a/dotfiles/core.py b/dotfiles/core.py index 3a6b8f2..6615651 100644 --- a/dotfiles/core.py +++ b/dotfiles/core.py @@ -37,7 +37,8 @@ class Dotfile(object): os.symlink(self.target, self.name) elif self.status == 'unsynced': if not force: - print "Skipping \"%s\", use --force to override" % self.basename + print("Skipping \"%s\", use --force to override" + % self.basename) return if os.path.isdir(self.name) and not os.path.islink(self.name): shutil.rmtree(self.name) @@ -47,17 +48,17 @@ class Dotfile(object): def add(self): if self.status == 'missing': - print "Skipping \"%s\", file not found" % self.basename + print("Skipping \"%s\", file not found" % self.basename) return if self.status == '': - print "Skipping \"%s\", already managed" % self.basename + print("Skipping \"%s\", already managed" % self.basename) return shutil.move(self.name, self.target) os.symlink(self.target, self.name) def remove(self): if self.status != '': - print "Skipping \"%s\", file is %s" % (self.basename, self.status) + print("Skipping \"%s\", file is %s" % (self.basename, self.status)) return os.remove(self.name) shutil.move(self.target, self.name) @@ -74,8 +75,9 @@ class Dotfiles(object): def __init__(self, **kwargs): # Map args from kwargs to instance-local variables - map(lambda k, v: (k in self.__attrs__) and setattr(self, k, v), - kwargs.iterkeys(), kwargs.itervalues()) + for k, v in kwargs.items(): + if k in self.__attrs__: + setattr(self, k, v) self._load() @@ -111,7 +113,7 @@ class Dotfiles(object): for dotfile in sorted(self.dotfiles, key=lambda dotfile: dotfile.name): if dotfile.status or verbose: - print dotfile + print(dotfile) def check(self): """List only unsynced and/or missing dotfiles.""" @@ -142,7 +144,7 @@ class Dotfiles(object): if os.path.basename(file).startswith('.'): getattr(Dotfile(file, self._fqpn(file), self.homedir), action)() else: - print "Skipping \"%s\", not a dotfile" % file + print("Skipping \"%s\", not a dotfile" % file) def move(self, target): """Move the repository to another location.""" diff --git a/test_dotfiles.py b/test_dotfiles.py index 8ee3a76..b892003 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -12,7 +12,7 @@ from dotfiles import core def touch(fname, times=None): - with file(fname, 'a'): + with open(fname, 'a'): os.utime(fname, times) |