diff options
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 65 |
1 files changed, 51 insertions, 14 deletions
@@ -16,6 +16,7 @@ from __future__ import print_function | |||
16 | import contextlib | 16 | import contextlib |
17 | import errno | 17 | import errno |
18 | import filecmp | 18 | import filecmp |
19 | import glob | ||
19 | import os | 20 | import os |
20 | import random | 21 | import random |
21 | import re | 22 | import re |
@@ -233,28 +234,60 @@ class _CopyFile(object): | |||
233 | _error('Cannot copy file %s to %s', src, dest) | 234 | _error('Cannot copy file %s to %s', src, dest) |
234 | 235 | ||
235 | class _LinkFile(object): | 236 | class _LinkFile(object): |
236 | def __init__(self, src, dest, abssrc, absdest): | 237 | def __init__(self, git_worktree, src, dest, relsrc, absdest): |
238 | self.git_worktree = git_worktree | ||
237 | self.src = src | 239 | self.src = src |
238 | self.dest = dest | 240 | self.dest = dest |
239 | self.abs_src = abssrc | 241 | self.src_rel_to_dest = relsrc |
240 | self.abs_dest = absdest | 242 | self.abs_dest = absdest |
241 | 243 | ||
242 | def _Link(self): | 244 | def __linkIt(self, relSrc, absDest): |
243 | src = self.abs_src | ||
244 | dest = self.abs_dest | ||
245 | # link file if it does not exist or is out of date | 245 | # link file if it does not exist or is out of date |
246 | if not os.path.islink(dest) or os.readlink(dest) != src: | 246 | if not os.path.islink(absDest) or (os.readlink(absDest) != relSrc): |
247 | try: | 247 | try: |
248 | # remove existing file first, since it might be read-only | 248 | # remove existing file first, since it might be read-only |
249 | if os.path.exists(dest): | 249 | if os.path.exists(absDest): |
250 | os.remove(dest) | 250 | os.remove(absDest) |
251 | else: | 251 | else: |
252 | dest_dir = os.path.dirname(dest) | 252 | dest_dir = os.path.dirname(absDest) |
253 | if not os.path.isdir(dest_dir): | 253 | if not os.path.isdir(dest_dir): |
254 | os.makedirs(dest_dir) | 254 | os.makedirs(dest_dir) |
255 | os.symlink(src, dest) | 255 | os.symlink(relSrc, absDest) |
256 | except IOError: | 256 | except IOError: |
257 | _error('Cannot link file %s to %s', src, dest) | 257 | _error('Cannot link file %s to %s', relSrc, absDest) |
258 | |||
259 | def _Link(self): | ||
260 | """Link the self.rel_src_to_dest and self.abs_dest. Handles wild cards | ||
261 | on the src linking all of the files in the source in to the destination | ||
262 | directory. | ||
263 | """ | ||
264 | # We use the absSrc to handle the situation where the current directory | ||
265 | # is not the root of the repo | ||
266 | absSrc = os.path.join(self.git_worktree, self.src) | ||
267 | if os.path.exists(absSrc): | ||
268 | # Entity exists so just a simple one to one link operation | ||
269 | self.__linkIt(self.src_rel_to_dest, self.abs_dest) | ||
270 | else: | ||
271 | # Entity doesn't exist assume there is a wild card | ||
272 | absDestDir = self.abs_dest | ||
273 | if os.path.exists(absDestDir) and not os.path.isdir(absDestDir): | ||
274 | _error('Link error: src with wildcard, %s must be a directory', | ||
275 | absDestDir) | ||
276 | else: | ||
277 | absSrcFiles = glob.glob(absSrc) | ||
278 | for absSrcFile in absSrcFiles: | ||
279 | # Create a releative path from source dir to destination dir | ||
280 | absSrcDir = os.path.dirname(absSrcFile) | ||
281 | relSrcDir = os.path.relpath(absSrcDir, absDestDir) | ||
282 | |||
283 | # Get the source file name | ||
284 | srcFile = os.path.basename(absSrcFile) | ||
285 | |||
286 | # Now form the final full paths to srcFile. They will be | ||
287 | # absolute for the desintaiton and relative for the srouce. | ||
288 | absDest = os.path.join(absDestDir, srcFile) | ||
289 | relSrc = os.path.join(relSrcDir, srcFile) | ||
290 | self.__linkIt(relSrc, absDest) | ||
258 | 291 | ||
259 | class RemoteSpec(object): | 292 | class RemoteSpec(object): |
260 | def __init__(self, | 293 | def __init__(self, |
@@ -1359,9 +1392,10 @@ class Project(object): | |||
1359 | 1392 | ||
1360 | def AddLinkFile(self, src, dest, absdest): | 1393 | def AddLinkFile(self, src, dest, absdest): |
1361 | # dest should already be an absolute path, but src is project relative | 1394 | # dest should already be an absolute path, but src is project relative |
1362 | # make src an absolute path | 1395 | # make src relative path to dest |
1363 | abssrc = os.path.join(self.worktree, src) | 1396 | absdestdir = os.path.dirname(absdest) |
1364 | self.linkfiles.append(_LinkFile(src, dest, abssrc, absdest)) | 1397 | relsrc = os.path.relpath(os.path.join(self.worktree, src), absdestdir) |
1398 | self.linkfiles.append(_LinkFile(self.worktree, src, dest, relsrc, absdest)) | ||
1365 | 1399 | ||
1366 | def AddAnnotation(self, name, value, keep): | 1400 | def AddAnnotation(self, name, value, keep): |
1367 | self.annotations.append(_Annotation(name, value, keep)) | 1401 | self.annotations.append(_Annotation(name, value, keep)) |
@@ -1908,6 +1942,9 @@ class Project(object): | |||
1908 | # mode, we just tried sync'ing from the upstream field; it doesn't exist, thus | 1942 | # mode, we just tried sync'ing from the upstream field; it doesn't exist, thus |
1909 | # abort the optimization attempt and do a full sync. | 1943 | # abort the optimization attempt and do a full sync. |
1910 | break | 1944 | break |
1945 | elif ret < 0: | ||
1946 | # Git died with a signal, exit immediately | ||
1947 | break | ||
1911 | time.sleep(random.randint(30, 45)) | 1948 | time.sleep(random.randint(30, 45)) |
1912 | 1949 | ||
1913 | if initial: | 1950 | if initial: |