diff options
Diffstat (limited to 'project.py')
| -rwxr-xr-x | project.py | 17 |
1 files changed, 4 insertions, 13 deletions
| @@ -58,11 +58,8 @@ else: | |||
| 58 | def _lwrite(path, content): | 58 | def _lwrite(path, content): |
| 59 | lock = '%s.lock' % path | 59 | lock = '%s.lock' % path |
| 60 | 60 | ||
| 61 | fd = open(lock, 'w') | 61 | with open(lock, 'w') as fd: |
| 62 | try: | ||
| 63 | fd.write(content) | 62 | fd.write(content) |
| 64 | finally: | ||
| 65 | fd.close() | ||
| 66 | 63 | ||
| 67 | try: | 64 | try: |
| 68 | platform_utils.rename(lock, path) | 65 | platform_utils.rename(lock, path) |
| @@ -1393,12 +1390,9 @@ class Project(object): | |||
| 1393 | if is_new: | 1390 | if is_new: |
| 1394 | alt = os.path.join(self.gitdir, 'objects/info/alternates') | 1391 | alt = os.path.join(self.gitdir, 'objects/info/alternates') |
| 1395 | try: | 1392 | try: |
| 1396 | fd = open(alt) | 1393 | with open(alt) as fd: |
| 1397 | try: | ||
| 1398 | # This works for both absolute and relative alternate directories. | 1394 | # This works for both absolute and relative alternate directories. |
| 1399 | alt_dir = os.path.join(self.objdir, 'objects', fd.readline().rstrip()) | 1395 | alt_dir = os.path.join(self.objdir, 'objects', fd.readline().rstrip()) |
| 1400 | finally: | ||
| 1401 | fd.close() | ||
| 1402 | except IOError: | 1396 | except IOError: |
| 1403 | alt_dir = None | 1397 | alt_dir = None |
| 1404 | else: | 1398 | else: |
| @@ -2893,14 +2887,11 @@ class Project(object): | |||
| 2893 | else: | 2887 | else: |
| 2894 | path = os.path.join(self._project.worktree, '.git', HEAD) | 2888 | path = os.path.join(self._project.worktree, '.git', HEAD) |
| 2895 | try: | 2889 | try: |
| 2896 | fd = open(path) | 2890 | with open(path) as fd: |
| 2891 | line = fd.readline() | ||
| 2897 | except IOError as e: | 2892 | except IOError as e: |
| 2898 | raise NoManifestException(path, str(e)) | 2893 | raise NoManifestException(path, str(e)) |
| 2899 | try: | 2894 | try: |
| 2900 | line = fd.readline() | ||
| 2901 | finally: | ||
| 2902 | fd.close() | ||
| 2903 | try: | ||
| 2904 | line = line.decode() | 2895 | line = line.decode() |
| 2905 | except AttributeError: | 2896 | except AttributeError: |
| 2906 | pass | 2897 | pass |
