cleanup: convert exceptions to OSError
In Python 3, these exceptions were merged into OSError, so switch
everything over to that.
Change-Id: If876a28b692de5aa5c62a3bdc8c000793ce52c63
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/390376
Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Mike Frysinger <vapier@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
diff --git a/git_config.py b/git_config.py
index 1bde479..6aa8d85 100644
--- a/git_config.py
+++ b/git_config.py
@@ -370,7 +370,7 @@
with Trace(": parsing %s", self.file):
with open(self._json) as fd:
return json.load(fd)
- except (IOError, ValueError):
+ except (OSError, ValueError):
platform_utils.remove(self._json, missing_ok=True)
return None
@@ -378,7 +378,7 @@
try:
with open(self._json, "w") as fd:
json.dump(cache, fd, indent=2)
- except (IOError, TypeError):
+ except (OSError, TypeError):
platform_utils.remove(self._json, missing_ok=True)
def _ReadGit(self):
diff --git a/git_refs.py b/git_refs.py
index bf7aa4a..237c15a 100644
--- a/git_refs.py
+++ b/git_refs.py
@@ -107,8 +107,6 @@
try:
fd = open(path)
mtime = os.path.getmtime(path)
- except IOError:
- return
except OSError:
return
try:
diff --git a/git_superproject.py b/git_superproject.py
index 651b6db..b80f013 100644
--- a/git_superproject.py
+++ b/git_superproject.py
@@ -381,7 +381,7 @@
try:
with open(manifest_path, "w", encoding="utf-8") as fp:
fp.write(manifest_str)
- except IOError as e:
+ except OSError as e:
self._LogError("cannot write manifest to : {} {}", manifest_path, e)
return None
return manifest_path
diff --git a/main.py b/main.py
index a128285..bd8d513 100755
--- a/main.py
+++ b/main.py
@@ -789,7 +789,7 @@
mgr.add_password(p[1], "https://%s/" % host, p[0], p[2])
except netrc.NetrcParseError:
pass
- except IOError:
+ except OSError:
pass
handlers.append(_BasicAuthHandler(mgr))
handlers.append(_DigestAuthHandler(mgr))
diff --git a/project.py b/project.py
index 5c9f31c..be53def 100644
--- a/project.py
+++ b/project.py
@@ -431,7 +431,7 @@
mode = os.stat(dest)[stat.ST_MODE]
mode = mode & ~(stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
os.chmod(dest, mode)
- except IOError:
+ except OSError:
logger.error("error: Cannot copy file %s to %s", src, dest)
@@ -466,7 +466,7 @@
if not platform_utils.isdir(dest_dir):
os.makedirs(dest_dir)
platform_utils.symlink(relSrc, absDest)
- except IOError:
+ except OSError:
logger.error(
"error: Cannot link file %s to %s", relSrc, absDest
)
@@ -1198,7 +1198,7 @@
with tarfile.open(tarpath, "r") as tar:
tar.extractall(path=path)
return True
- except (IOError, tarfile.TarError) as e:
+ except (OSError, tarfile.TarError) as e:
logger.error("error: Cannot extract archive %s: %s", tarpath, e)
return False
@@ -1309,7 +1309,7 @@
alt_dir = os.path.join(
self.objdir, "objects", fd.readline().rstrip()
)
- except IOError:
+ except OSError:
alt_dir = None
else:
alt_dir = None
@@ -3584,7 +3584,7 @@
try:
with open(path) as fd:
line = fd.readline()
- except IOError as e:
+ except OSError as e:
raise NoManifestException(path, str(e))
try:
line = line.decode()
diff --git a/repo b/repo
index 6b39f22..a9ae4fa 100755
--- a/repo
+++ b/repo
@@ -627,7 +627,7 @@
match = re.match("gitc_dir=(?P<gitc_manifest_dir>.*)", line)
if match:
_gitc_manifest_dir = match.group("gitc_manifest_dir")
- except IOError:
+ except OSError:
pass
return _gitc_manifest_dir
@@ -1277,7 +1277,7 @@
try:
with open(path, "rb") as f:
data = f.read()
- except EnvironmentError:
+ except OSError:
# NB: EnvironmentError is used for Python 2 & 3 compatibility.
# If we couldn't open the file, assume it's an old source tree.
return None
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 2309897..8460bce 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -21,7 +21,6 @@
import netrc
import optparse
import os
-import socket
import sys
import tempfile
import time
@@ -1376,7 +1375,7 @@
else:
try:
info = netrc.netrc()
- except IOError:
+ except OSError:
# .netrc file does not exist or could not be opened.
pass
else:
@@ -1435,7 +1434,7 @@
try:
with open(smart_sync_manifest_path, "w") as f:
f.write(manifest_str)
- except IOError as e:
+ except OSError as e:
raise SmartSyncError(
"error: cannot write manifest to %s:\n%s"
% (smart_sync_manifest_path, e),
@@ -1446,7 +1445,7 @@
raise SmartSyncError(
"error: manifest server RPC call failed: %s" % manifest_str
)
- except (socket.error, IOError, xmlrpc.client.Fault) as e:
+ except (OSError, xmlrpc.client.Fault) as e:
raise SmartSyncError(
"error: cannot connect to manifest server %s:\n%s"
% (manifest.manifest_server, e),
@@ -1931,7 +1930,7 @@
try:
with open(self._path) as f:
self._saved = json.load(f)
- except (IOError, ValueError):
+ except (OSError, ValueError):
platform_utils.remove(self._path, missing_ok=True)
self._saved = {}
@@ -1947,7 +1946,7 @@
try:
with open(self._path, "w") as f:
json.dump(self._seen, f, indent=2)
- except (IOError, TypeError):
+ except (OSError, TypeError):
platform_utils.remove(self._path, missing_ok=True)
@@ -1994,7 +1993,7 @@
try:
with open(self._path) as f:
self._state = json.load(f)
- except (IOError, ValueError):
+ except (OSError, ValueError):
platform_utils.remove(self._path, missing_ok=True)
self._state = {}
@@ -2004,7 +2003,7 @@
try:
with open(self._path, "w") as f:
json.dump(self._state, f, indent=2)
- except (IOError, TypeError):
+ except (OSError, TypeError):
platform_utils.remove(self._path, missing_ok=True)
def PruneRemovedProjects(self):
@@ -2137,7 +2136,7 @@
try:
p.feed(data)
except xml.parsers.expat.ExpatError as e:
- raise IOError(
+ raise OSError(
f"Parsing the manifest failed: {e}\n"
f"Please report this to your manifest server admin.\n"
f'Here is the full response:\n{data.decode("utf-8")}'