summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2023-10-20 23:32:40 +0545
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-10-21 00:56:10 +0000
commitae824fb2fc2770c84cc34c1956e4c76c8c972860 (patch)
tree4f8ec44e29c7401b99b3aef1b28a2104a0a86221
parent034950b9eebacd6598ea518a0b254845bc806ab6 (diff)
downloadgit-repo-ae824fb2fc2770c84cc34c1956e4c76c8c972860.tar.gz
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>
-rw-r--r--git_config.py4
-rw-r--r--git_refs.py2
-rw-r--r--git_superproject.py2
-rwxr-xr-xmain.py2
-rw-r--r--project.py10
-rwxr-xr-xrepo4
-rw-r--r--subcmds/sync.py17
7 files changed, 19 insertions, 22 deletions
diff --git a/git_config.py b/git_config.py
index 1bde4795..6aa8d855 100644
--- a/git_config.py
+++ b/git_config.py
@@ -370,7 +370,7 @@ class GitConfig:
370 with Trace(": parsing %s", self.file): 370 with Trace(": parsing %s", self.file):
371 with open(self._json) as fd: 371 with open(self._json) as fd:
372 return json.load(fd) 372 return json.load(fd)
373 except (IOError, ValueError): 373 except (OSError, ValueError):
374 platform_utils.remove(self._json, missing_ok=True) 374 platform_utils.remove(self._json, missing_ok=True)
375 return None 375 return None
376 376
@@ -378,7 +378,7 @@ class GitConfig:
378 try: 378 try:
379 with open(self._json, "w") as fd: 379 with open(self._json, "w") as fd:
380 json.dump(cache, fd, indent=2) 380 json.dump(cache, fd, indent=2)
381 except (IOError, TypeError): 381 except (OSError, TypeError):
382 platform_utils.remove(self._json, missing_ok=True) 382 platform_utils.remove(self._json, missing_ok=True)
383 383
384 def _ReadGit(self): 384 def _ReadGit(self):
diff --git a/git_refs.py b/git_refs.py
index bf7aa4a1..237c15ae 100644
--- a/git_refs.py
+++ b/git_refs.py
@@ -107,8 +107,6 @@ class GitRefs:
107 try: 107 try:
108 fd = open(path) 108 fd = open(path)
109 mtime = os.path.getmtime(path) 109 mtime = os.path.getmtime(path)
110 except IOError:
111 return
112 except OSError: 110 except OSError:
113 return 111 return
114 try: 112 try:
diff --git a/git_superproject.py b/git_superproject.py
index 651b6dbb..b80f0130 100644
--- a/git_superproject.py
+++ b/git_superproject.py
@@ -381,7 +381,7 @@ class Superproject:
381 try: 381 try:
382 with open(manifest_path, "w", encoding="utf-8") as fp: 382 with open(manifest_path, "w", encoding="utf-8") as fp:
383 fp.write(manifest_str) 383 fp.write(manifest_str)
384 except IOError as e: 384 except OSError as e:
385 self._LogError("cannot write manifest to : {} {}", manifest_path, e) 385 self._LogError("cannot write manifest to : {} {}", manifest_path, e)
386 return None 386 return None
387 return manifest_path 387 return manifest_path
diff --git a/main.py b/main.py
index a1282851..bd8d5135 100755
--- a/main.py
+++ b/main.py
@@ -789,7 +789,7 @@ def init_http():
789 mgr.add_password(p[1], "https://%s/" % host, p[0], p[2]) 789 mgr.add_password(p[1], "https://%s/" % host, p[0], p[2])
790 except netrc.NetrcParseError: 790 except netrc.NetrcParseError:
791 pass 791 pass
792 except IOError: 792 except OSError:
793 pass 793 pass
794 handlers.append(_BasicAuthHandler(mgr)) 794 handlers.append(_BasicAuthHandler(mgr))
795 handlers.append(_DigestAuthHandler(mgr)) 795 handlers.append(_DigestAuthHandler(mgr))
diff --git a/project.py b/project.py
index 5c9f31cf..be53defd 100644
--- a/project.py
+++ b/project.py
@@ -431,7 +431,7 @@ class _CopyFile:
431 mode = os.stat(dest)[stat.ST_MODE] 431 mode = os.stat(dest)[stat.ST_MODE]
432 mode = mode & ~(stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH) 432 mode = mode & ~(stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
433 os.chmod(dest, mode) 433 os.chmod(dest, mode)
434 except IOError: 434 except OSError:
435 logger.error("error: Cannot copy file %s to %s", src, dest) 435 logger.error("error: Cannot copy file %s to %s", src, dest)
436 436
437 437
@@ -466,7 +466,7 @@ class _LinkFile:
466 if not platform_utils.isdir(dest_dir): 466 if not platform_utils.isdir(dest_dir):
467 os.makedirs(dest_dir) 467 os.makedirs(dest_dir)
468 platform_utils.symlink(relSrc, absDest) 468 platform_utils.symlink(relSrc, absDest)
469 except IOError: 469 except OSError:
470 logger.error( 470 logger.error(
471 "error: Cannot link file %s to %s", relSrc, absDest 471 "error: Cannot link file %s to %s", relSrc, absDest
472 ) 472 )
@@ -1198,7 +1198,7 @@ class Project:
1198 with tarfile.open(tarpath, "r") as tar: 1198 with tarfile.open(tarpath, "r") as tar:
1199 tar.extractall(path=path) 1199 tar.extractall(path=path)
1200 return True 1200 return True
1201 except (IOError, tarfile.TarError) as e: 1201 except (OSError, tarfile.TarError) as e:
1202 logger.error("error: Cannot extract archive %s: %s", tarpath, e) 1202 logger.error("error: Cannot extract archive %s: %s", tarpath, e)
1203 return False 1203 return False
1204 1204
@@ -1309,7 +1309,7 @@ class Project:
1309 alt_dir = os.path.join( 1309 alt_dir = os.path.join(
1310 self.objdir, "objects", fd.readline().rstrip() 1310 self.objdir, "objects", fd.readline().rstrip()
1311 ) 1311 )
1312 except IOError: 1312 except OSError:
1313 alt_dir = None 1313 alt_dir = None
1314 else: 1314 else:
1315 alt_dir = None 1315 alt_dir = None
@@ -3584,7 +3584,7 @@ class Project:
3584 try: 3584 try:
3585 with open(path) as fd: 3585 with open(path) as fd:
3586 line = fd.readline() 3586 line = fd.readline()
3587 except IOError as e: 3587 except OSError as e:
3588 raise NoManifestException(path, str(e)) 3588 raise NoManifestException(path, str(e))
3589 try: 3589 try:
3590 line = line.decode() 3590 line = line.decode()
diff --git a/repo b/repo
index 6b39f227..a9ae4fa7 100755
--- a/repo
+++ b/repo
@@ -627,7 +627,7 @@ def get_gitc_manifest_dir():
627 match = re.match("gitc_dir=(?P<gitc_manifest_dir>.*)", line) 627 match = re.match("gitc_dir=(?P<gitc_manifest_dir>.*)", line)
628 if match: 628 if match:
629 _gitc_manifest_dir = match.group("gitc_manifest_dir") 629 _gitc_manifest_dir = match.group("gitc_manifest_dir")
630 except IOError: 630 except OSError:
631 pass 631 pass
632 return _gitc_manifest_dir 632 return _gitc_manifest_dir
633 633
@@ -1277,7 +1277,7 @@ class Requirements:
1277 try: 1277 try:
1278 with open(path, "rb") as f: 1278 with open(path, "rb") as f:
1279 data = f.read() 1279 data = f.read()
1280 except EnvironmentError: 1280 except OSError:
1281 # NB: EnvironmentError is used for Python 2 & 3 compatibility. 1281 # NB: EnvironmentError is used for Python 2 & 3 compatibility.
1282 # If we couldn't open the file, assume it's an old source tree. 1282 # If we couldn't open the file, assume it's an old source tree.
1283 return None 1283 return None
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 23098972..8460bcec 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -21,7 +21,6 @@ import multiprocessing
21import netrc 21import netrc
22import optparse 22import optparse
23import os 23import os
24import socket
25import sys 24import sys
26import tempfile 25import tempfile
27import time 26import time
@@ -1376,7 +1375,7 @@ later is required to fix a server side protocol bug.
1376 else: 1375 else:
1377 try: 1376 try:
1378 info = netrc.netrc() 1377 info = netrc.netrc()
1379 except IOError: 1378 except OSError:
1380 # .netrc file does not exist or could not be opened. 1379 # .netrc file does not exist or could not be opened.
1381 pass 1380 pass
1382 else: 1381 else:
@@ -1435,7 +1434,7 @@ later is required to fix a server side protocol bug.
1435 try: 1434 try:
1436 with open(smart_sync_manifest_path, "w") as f: 1435 with open(smart_sync_manifest_path, "w") as f:
1437 f.write(manifest_str) 1436 f.write(manifest_str)
1438 except IOError as e: 1437 except OSError as e:
1439 raise SmartSyncError( 1438 raise SmartSyncError(
1440 "error: cannot write manifest to %s:\n%s" 1439 "error: cannot write manifest to %s:\n%s"
1441 % (smart_sync_manifest_path, e), 1440 % (smart_sync_manifest_path, e),
@@ -1446,7 +1445,7 @@ later is required to fix a server side protocol bug.
1446 raise SmartSyncError( 1445 raise SmartSyncError(
1447 "error: manifest server RPC call failed: %s" % manifest_str 1446 "error: manifest server RPC call failed: %s" % manifest_str
1448 ) 1447 )
1449 except (socket.error, IOError, xmlrpc.client.Fault) as e: 1448 except (OSError, xmlrpc.client.Fault) as e:
1450 raise SmartSyncError( 1449 raise SmartSyncError(
1451 "error: cannot connect to manifest server %s:\n%s" 1450 "error: cannot connect to manifest server %s:\n%s"
1452 % (manifest.manifest_server, e), 1451 % (manifest.manifest_server, e),
@@ -1931,7 +1930,7 @@ class _FetchTimes:
1931 try: 1930 try:
1932 with open(self._path) as f: 1931 with open(self._path) as f:
1933 self._saved = json.load(f) 1932 self._saved = json.load(f)
1934 except (IOError, ValueError): 1933 except (OSError, ValueError):
1935 platform_utils.remove(self._path, missing_ok=True) 1934 platform_utils.remove(self._path, missing_ok=True)
1936 self._saved = {} 1935 self._saved = {}
1937 1936
@@ -1947,7 +1946,7 @@ class _FetchTimes:
1947 try: 1946 try:
1948 with open(self._path, "w") as f: 1947 with open(self._path, "w") as f:
1949 json.dump(self._seen, f, indent=2) 1948 json.dump(self._seen, f, indent=2)
1950 except (IOError, TypeError): 1949 except (OSError, TypeError):
1951 platform_utils.remove(self._path, missing_ok=True) 1950 platform_utils.remove(self._path, missing_ok=True)
1952 1951
1953 1952
@@ -1994,7 +1993,7 @@ class LocalSyncState:
1994 try: 1993 try:
1995 with open(self._path) as f: 1994 with open(self._path) as f:
1996 self._state = json.load(f) 1995 self._state = json.load(f)
1997 except (IOError, ValueError): 1996 except (OSError, ValueError):
1998 platform_utils.remove(self._path, missing_ok=True) 1997 platform_utils.remove(self._path, missing_ok=True)
1999 self._state = {} 1998 self._state = {}
2000 1999
@@ -2004,7 +2003,7 @@ class LocalSyncState:
2004 try: 2003 try:
2005 with open(self._path, "w") as f: 2004 with open(self._path, "w") as f:
2006 json.dump(self._state, f, indent=2) 2005 json.dump(self._state, f, indent=2)
2007 except (IOError, TypeError): 2006 except (OSError, TypeError):
2008 platform_utils.remove(self._path, missing_ok=True) 2007 platform_utils.remove(self._path, missing_ok=True)
2009 2008
2010 def PruneRemovedProjects(self): 2009 def PruneRemovedProjects(self):
@@ -2137,7 +2136,7 @@ class PersistentTransport(xmlrpc.client.Transport):
2137 try: 2136 try:
2138 p.feed(data) 2137 p.feed(data)
2139 except xml.parsers.expat.ExpatError as e: 2138 except xml.parsers.expat.ExpatError as e:
2140 raise IOError( 2139 raise OSError(
2141 f"Parsing the manifest failed: {e}\n" 2140 f"Parsing the manifest failed: {e}\n"
2142 f"Please report this to your manifest server admin.\n" 2141 f"Please report this to your manifest server admin.\n"
2143 f'Here is the full response:\n{data.decode("utf-8")}' 2142 f'Here is the full response:\n{data.decode("utf-8")}'