1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 | diff --git a/usd-import b/usd-import
index a9e2925..71fb96d 100755
--- a/usd-import
+++ b/usd-import
@@ -49,6 +49,15 @@ except ImportError:
logging.error('Is %s installed?', pkg)
sys.exit(1)
+def _open_any(paths, *args, **kwargs):
+ for path in paths:
+ try:
+ f = open(path, args, kwargs)
+ return f
+ except FileNotFoundError:
+ pass
+ raise FileNotFoundError
+
class USDGitRepository:
def __init__(self, pkgname, local_dir, remote_url, owner, user):
if local_dir is None:
@@ -434,7 +443,17 @@ class USDGitRepository:
os.chdir(self._local_repo.workdir)
try:
- with open(patch_override['patch']) as f:
+ with _open_any(patch_override['patch'],
+ os.path.join(os.getcwd(),
+ patch_override['patch']
+ ),
+ os.path.join(
+ os.path.dirname(
+ os.path.abspath(__file__)
+ ),
+ patch_override['patch']
+ )
+ ) as f:
subprocess.run(
'patch -p1 < %s' % f.name,
check=True,
@@ -443,30 +462,8 @@ class USDGitRepository:
)
fixed_import_tree_hash = ''
except FileNotFoundError:
- try:
- with open(os.path.join(os.getcwd(),
- patch_override['patch'])) as f:
- subprocess.run(
- 'patch -p1 < %s' % f.name,
- check=True,
- shell=True,
- env=self._env
- )
- fixed_import_tree_hash = ''
- except FileNotFoundError:
- try:
- with open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
- patch_override['patch'])) as f:
- subprocess.run(
- 'patch -p1 < %s' % f.name,
- check=True,
- shell=True,
- env=self._env
- )
- fixed_import_tree_hash = ''
- except FileNotFoundError:
- logging.error('Unable to find patch file %s' % patch_override['patch'])
- sys.exit(1)
+ logging.error('Unable to find patch file %s' % patch_override['patch'])
+ sys.exit(1)
changelog_version, previous_changelog_version = \
self.get_changelog_versions_from_treeish(fixed_import_tree_hash)
@@ -865,19 +862,18 @@ def parse_parentfile(pkgname, parentfile):
parent_overrides = dict()
if parentfile is None:
try:
- parentfile = open(os.path.join(os.getcwd(),
- "parent_overrides.txt"
- )
- )
+ parentfile = _open_any(os.path.join(os.getcwd(),
+ "parent_overrides.txt"
+ ),
+ os.path.join(
+ os.path.dirname(
+ os.path.abspath(__file__)
+ ),
+ "parent_overrides.txt"
+ )
+ )
except FileNotFoundError:
- try:
- parentfile = open(os.path.join(
- os.path.dirname(os.path.abspath(__file__)),
- "parent_overrides.txt"
- )
- )
- except FileNotFoundError:
- return parent_overrides
+ return parent_overrides
for line in parentfile:
if line.startswith('#'):
continue
@@ -899,19 +895,18 @@ def parse_patchfile(pkgname, patchfile):
patch_overrides = list()
if patchfile is None:
try:
- patchfile = open(os.path.join(os.getcwd(),
- "patch_overrides.txt"
- )
- )
- except FileNotFoundError:
- try:
- patchfile = open(os.path.join(
- os.path.dirname(os.path.abspath(__file__)),
- "patch_overrides.txt"
+ patchfile = _open_any(os.path.join(os.getcwd(),
+ "patch_overrides.txt"
+ ),
+ os.path.join(
+ os.path.dirname(
+ os.path.abspath(__file__)
+ ),
+ "patch_overrides.txt"
)
- )
- except FileNotFoundError:
- return patch_overrides
+ )
+ except FileNotFoundError:
+ return patch_overrides
for line in patchfile:
if line.startswith('#'):
continue
|