mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
034950b9ee
commit
ae824fb2fc
@ -370,7 +370,7 @@ class GitConfig:
|
|||||||
with Trace(": parsing %s", self.file):
|
with Trace(": parsing %s", self.file):
|
||||||
with open(self._json) as fd:
|
with open(self._json) as fd:
|
||||||
return json.load(fd)
|
return json.load(fd)
|
||||||
except (IOError, ValueError):
|
except (OSError, ValueError):
|
||||||
platform_utils.remove(self._json, missing_ok=True)
|
platform_utils.remove(self._json, missing_ok=True)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -378,7 +378,7 @@ class GitConfig:
|
|||||||
try:
|
try:
|
||||||
with open(self._json, "w") as fd:
|
with open(self._json, "w") as fd:
|
||||||
json.dump(cache, fd, indent=2)
|
json.dump(cache, fd, indent=2)
|
||||||
except (IOError, TypeError):
|
except (OSError, TypeError):
|
||||||
platform_utils.remove(self._json, missing_ok=True)
|
platform_utils.remove(self._json, missing_ok=True)
|
||||||
|
|
||||||
def _ReadGit(self):
|
def _ReadGit(self):
|
||||||
|
@ -107,8 +107,6 @@ class GitRefs:
|
|||||||
try:
|
try:
|
||||||
fd = open(path)
|
fd = open(path)
|
||||||
mtime = os.path.getmtime(path)
|
mtime = os.path.getmtime(path)
|
||||||
except IOError:
|
|
||||||
return
|
|
||||||
except OSError:
|
except OSError:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
|
@ -381,7 +381,7 @@ class Superproject:
|
|||||||
try:
|
try:
|
||||||
with open(manifest_path, "w", encoding="utf-8") as fp:
|
with open(manifest_path, "w", encoding="utf-8") as fp:
|
||||||
fp.write(manifest_str)
|
fp.write(manifest_str)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
self._LogError("cannot write manifest to : {} {}", manifest_path, e)
|
self._LogError("cannot write manifest to : {} {}", manifest_path, e)
|
||||||
return None
|
return None
|
||||||
return manifest_path
|
return manifest_path
|
||||||
|
2
main.py
2
main.py
@ -789,7 +789,7 @@ def init_http():
|
|||||||
mgr.add_password(p[1], "https://%s/" % host, p[0], p[2])
|
mgr.add_password(p[1], "https://%s/" % host, p[0], p[2])
|
||||||
except netrc.NetrcParseError:
|
except netrc.NetrcParseError:
|
||||||
pass
|
pass
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
handlers.append(_BasicAuthHandler(mgr))
|
handlers.append(_BasicAuthHandler(mgr))
|
||||||
handlers.append(_DigestAuthHandler(mgr))
|
handlers.append(_DigestAuthHandler(mgr))
|
||||||
|
10
project.py
10
project.py
@ -431,7 +431,7 @@ class _CopyFile:
|
|||||||
mode = os.stat(dest)[stat.ST_MODE]
|
mode = os.stat(dest)[stat.ST_MODE]
|
||||||
mode = mode & ~(stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
|
mode = mode & ~(stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
|
||||||
os.chmod(dest, mode)
|
os.chmod(dest, mode)
|
||||||
except IOError:
|
except OSError:
|
||||||
logger.error("error: Cannot copy file %s to %s", src, dest)
|
logger.error("error: Cannot copy file %s to %s", src, dest)
|
||||||
|
|
||||||
|
|
||||||
@ -466,7 +466,7 @@ class _LinkFile:
|
|||||||
if not platform_utils.isdir(dest_dir):
|
if not platform_utils.isdir(dest_dir):
|
||||||
os.makedirs(dest_dir)
|
os.makedirs(dest_dir)
|
||||||
platform_utils.symlink(relSrc, absDest)
|
platform_utils.symlink(relSrc, absDest)
|
||||||
except IOError:
|
except OSError:
|
||||||
logger.error(
|
logger.error(
|
||||||
"error: Cannot link file %s to %s", relSrc, absDest
|
"error: Cannot link file %s to %s", relSrc, absDest
|
||||||
)
|
)
|
||||||
@ -1198,7 +1198,7 @@ class Project:
|
|||||||
with tarfile.open(tarpath, "r") as tar:
|
with tarfile.open(tarpath, "r") as tar:
|
||||||
tar.extractall(path=path)
|
tar.extractall(path=path)
|
||||||
return True
|
return True
|
||||||
except (IOError, tarfile.TarError) as e:
|
except (OSError, tarfile.TarError) as e:
|
||||||
logger.error("error: Cannot extract archive %s: %s", tarpath, e)
|
logger.error("error: Cannot extract archive %s: %s", tarpath, e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1309,7 +1309,7 @@ class Project:
|
|||||||
alt_dir = os.path.join(
|
alt_dir = os.path.join(
|
||||||
self.objdir, "objects", fd.readline().rstrip()
|
self.objdir, "objects", fd.readline().rstrip()
|
||||||
)
|
)
|
||||||
except IOError:
|
except OSError:
|
||||||
alt_dir = None
|
alt_dir = None
|
||||||
else:
|
else:
|
||||||
alt_dir = None
|
alt_dir = None
|
||||||
@ -3584,7 +3584,7 @@ class Project:
|
|||||||
try:
|
try:
|
||||||
with open(path) as fd:
|
with open(path) as fd:
|
||||||
line = fd.readline()
|
line = fd.readline()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
raise NoManifestException(path, str(e))
|
raise NoManifestException(path, str(e))
|
||||||
try:
|
try:
|
||||||
line = line.decode()
|
line = line.decode()
|
||||||
|
4
repo
4
repo
@ -627,7 +627,7 @@ def get_gitc_manifest_dir():
|
|||||||
match = re.match("gitc_dir=(?P<gitc_manifest_dir>.*)", line)
|
match = re.match("gitc_dir=(?P<gitc_manifest_dir>.*)", line)
|
||||||
if match:
|
if match:
|
||||||
_gitc_manifest_dir = match.group("gitc_manifest_dir")
|
_gitc_manifest_dir = match.group("gitc_manifest_dir")
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
return _gitc_manifest_dir
|
return _gitc_manifest_dir
|
||||||
|
|
||||||
@ -1277,7 +1277,7 @@ class Requirements:
|
|||||||
try:
|
try:
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
except EnvironmentError:
|
except OSError:
|
||||||
# NB: EnvironmentError is used for Python 2 & 3 compatibility.
|
# NB: EnvironmentError is used for Python 2 & 3 compatibility.
|
||||||
# If we couldn't open the file, assume it's an old source tree.
|
# If we couldn't open the file, assume it's an old source tree.
|
||||||
return None
|
return None
|
||||||
|
@ -21,7 +21,6 @@ import multiprocessing
|
|||||||
import netrc
|
import netrc
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import socket
|
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
@ -1376,7 +1375,7 @@ later is required to fix a server side protocol bug.
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
info = netrc.netrc()
|
info = netrc.netrc()
|
||||||
except IOError:
|
except OSError:
|
||||||
# .netrc file does not exist or could not be opened.
|
# .netrc file does not exist or could not be opened.
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -1435,7 +1434,7 @@ later is required to fix a server side protocol bug.
|
|||||||
try:
|
try:
|
||||||
with open(smart_sync_manifest_path, "w") as f:
|
with open(smart_sync_manifest_path, "w") as f:
|
||||||
f.write(manifest_str)
|
f.write(manifest_str)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
raise SmartSyncError(
|
raise SmartSyncError(
|
||||||
"error: cannot write manifest to %s:\n%s"
|
"error: cannot write manifest to %s:\n%s"
|
||||||
% (smart_sync_manifest_path, e),
|
% (smart_sync_manifest_path, e),
|
||||||
@ -1446,7 +1445,7 @@ later is required to fix a server side protocol bug.
|
|||||||
raise SmartSyncError(
|
raise SmartSyncError(
|
||||||
"error: manifest server RPC call failed: %s" % manifest_str
|
"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(
|
raise SmartSyncError(
|
||||||
"error: cannot connect to manifest server %s:\n%s"
|
"error: cannot connect to manifest server %s:\n%s"
|
||||||
% (manifest.manifest_server, e),
|
% (manifest.manifest_server, e),
|
||||||
@ -1931,7 +1930,7 @@ class _FetchTimes:
|
|||||||
try:
|
try:
|
||||||
with open(self._path) as f:
|
with open(self._path) as f:
|
||||||
self._saved = json.load(f)
|
self._saved = json.load(f)
|
||||||
except (IOError, ValueError):
|
except (OSError, ValueError):
|
||||||
platform_utils.remove(self._path, missing_ok=True)
|
platform_utils.remove(self._path, missing_ok=True)
|
||||||
self._saved = {}
|
self._saved = {}
|
||||||
|
|
||||||
@ -1947,7 +1946,7 @@ class _FetchTimes:
|
|||||||
try:
|
try:
|
||||||
with open(self._path, "w") as f:
|
with open(self._path, "w") as f:
|
||||||
json.dump(self._seen, f, indent=2)
|
json.dump(self._seen, f, indent=2)
|
||||||
except (IOError, TypeError):
|
except (OSError, TypeError):
|
||||||
platform_utils.remove(self._path, missing_ok=True)
|
platform_utils.remove(self._path, missing_ok=True)
|
||||||
|
|
||||||
|
|
||||||
@ -1994,7 +1993,7 @@ class LocalSyncState:
|
|||||||
try:
|
try:
|
||||||
with open(self._path) as f:
|
with open(self._path) as f:
|
||||||
self._state = json.load(f)
|
self._state = json.load(f)
|
||||||
except (IOError, ValueError):
|
except (OSError, ValueError):
|
||||||
platform_utils.remove(self._path, missing_ok=True)
|
platform_utils.remove(self._path, missing_ok=True)
|
||||||
self._state = {}
|
self._state = {}
|
||||||
|
|
||||||
@ -2004,7 +2003,7 @@ class LocalSyncState:
|
|||||||
try:
|
try:
|
||||||
with open(self._path, "w") as f:
|
with open(self._path, "w") as f:
|
||||||
json.dump(self._state, f, indent=2)
|
json.dump(self._state, f, indent=2)
|
||||||
except (IOError, TypeError):
|
except (OSError, TypeError):
|
||||||
platform_utils.remove(self._path, missing_ok=True)
|
platform_utils.remove(self._path, missing_ok=True)
|
||||||
|
|
||||||
def PruneRemovedProjects(self):
|
def PruneRemovedProjects(self):
|
||||||
@ -2137,7 +2136,7 @@ class PersistentTransport(xmlrpc.client.Transport):
|
|||||||
try:
|
try:
|
||||||
p.feed(data)
|
p.feed(data)
|
||||||
except xml.parsers.expat.ExpatError as e:
|
except xml.parsers.expat.ExpatError as e:
|
||||||
raise IOError(
|
raise OSError(
|
||||||
f"Parsing the manifest failed: {e}\n"
|
f"Parsing the manifest failed: {e}\n"
|
||||||
f"Please report this to your manifest server admin.\n"
|
f"Please report this to your manifest server admin.\n"
|
||||||
f'Here is the full response:\n{data.decode("utf-8")}'
|
f'Here is the full response:\n{data.decode("utf-8")}'
|
||||||
|
Loading…
Reference in New Issue
Block a user