author | Clipperz <info@clipperz.com> | 2013-01-09 11:45:31 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-09 11:45:31 (UTC) |
commit | 9741a93a9f5c76827135b43c03b20c0a48f12604 (patch) (unidiff) | |
tree | 1a8fff379a033d873c9e1c7faff755fb6bb7b118 /scripts | |
parent | 8ef30d00eb96004c39540019336c0ec99dae01cb (diff) | |
download | clipperz-9741a93a9f5c76827135b43c03b20c0a48f12604.zip clipperz-9741a93a9f5c76827135b43c03b20c0a48f12604.tar.gz clipperz-9741a93a9f5c76827135b43c03b20c0a48f12604.tar.bz2 |
Merge latest changes with public repository
-rw-r--r-- | scripts/builder/repository.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/scripts/builder/repository.py b/scripts/builder/repository.py index 7ac2324..7a44e47 100644 --- a/scripts/builder/repository.py +++ b/scripts/builder/repository.py | |||
@@ -1,97 +1,99 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | # -*- coding: UTF-8 -*- | 2 | # -*- coding: UTF-8 -*- |
3 | 3 | ||
4 | 4 | ||
5 | def repositoryWithPath (path): | 5 | def repositoryWithPath (path): |
6 | try: | 6 | try: |
7 | from mercurial import ui, hg | 7 | from mercurial import ui, hg |
8 | 8 | ||
9 | repo = hg.repository(ui.ui(), path) | 9 | repo = hg.repository(ui.ui(), path) |
10 | result = HgRepository(repo, path) | 10 | result = HgRepository(repo, path) |
11 | except: | 11 | except: |
12 | try: | 12 | try: |
13 | from git import Repo | 13 | from git import Repo |
14 | repo = Repo(path) | 14 | repo = Repo(path) |
15 | result = GitRepository(repo, path) | 15 | result = GitRepository(repo, path) |
16 | |||
17 | except ImportError, exception: | 16 | except ImportError, exception: |
18 | print "Failed to import git, please install http://gitorious.org/git-python" | 17 | print "Failed to import git, please install http://gitorious.org/git-python" |
19 | raise exception | 18 | raise exception |
20 | except: | 19 | except: |
21 | result = SnapshotRepository('', path) | 20 | result = SnapshotRepository('', path) |
22 | 21 | ||
23 | 22 | ||
24 | return result | 23 | return result |
25 | 24 | ||
26 | 25 | ||
27 | #=================================================================== | 26 | #=================================================================== |
28 | 27 | ||
29 | 28 | ||
30 | class Repository(object): | 29 | class Repository(object): |
31 | 30 | ||
32 | def __init__ (self, repository, path): | 31 | def __init__ (self, repository, path): |
33 | self.repository = repository | 32 | self.repository = repository |
34 | self.path = path | 33 | self.path = path |
35 | 34 | ||
36 | 35 | ||
37 | def revision (self): | 36 | def revision (self): |
38 | raise NotImplementedError() | 37 | raise NotImplementedError() |
39 | 38 | ||
40 | 39 | ||
41 | def areTherePendingChanges (self): | 40 | def areTherePendingChanges (self): |
42 | raise NotImplementedError() | 41 | raise NotImplementedError() |
43 | 42 | ||
44 | 43 | ||
45 | def version (self): | 44 | def version (self): |
46 | result = self.revision() | 45 | result = self.revision() |
47 | if self.areTherePendingChanges(): | 46 | if self.areTherePendingChanges(): |
48 | result = '>>> ' + result + ' <<<' | 47 | result = '>>> ' + result + ' <<<' |
49 | 48 | ||
50 | # print "VERSION: " + result | 49 | # print "VERSION: " + result |
51 | return result | 50 | return result |
52 | 51 | ||
53 | 52 | ||
54 | #=================================================================== | 53 | #=================================================================== |
55 | 54 | ||
56 | 55 | ||
57 | class GitRepository(Repository): | 56 | class GitRepository(Repository): |
58 | #http://gitorious.org/git-python | 57 | #http://gitorious.org/git-python |
59 | 58 | ||
60 | def revision (self): | 59 | def revision (self): |
61 | try: | 60 | try: |
62 | return self.repository.head.commit.hexsha | 61 | return self.repository.head.commit.hexsha |
63 | except: | 62 | except: |
64 | return self.repository.commits()[0].id | 63 | return self.repository.commits()[0].id |
65 | 64 | ||
66 | 65 | ||
67 | def areTherePendingChanges (self): | 66 | def areTherePendingChanges (self): |
68 | try: | 67 | try: |
69 | return self.repository.is_dirty() | 68 | return self.repository.is_dirty() |
70 | except TypeError, te: | 69 | except TypeError, te: |
71 | return self.repository.is_dirty | 70 | return self.repository.is_dirty |
72 | 71 | ||
73 | 72 | ||
74 | 73 | ||
75 | #=================================================================== | 74 | #=================================================================== |
76 | 75 | ||
77 | 76 | ||
78 | class HgRepository(Repository): | 77 | class HgRepository(Repository): |
79 | #http://mercurial.selenic.com/wiki/MercurialApi | 78 | #http://mercurial.selenic.com/wiki/MercurialApi |
80 | 79 | ||
81 | def revision (self): | 80 | def revision (self): |
82 | return 'hg:' + str(self.repository['tip']) | 81 | return 'hg:' + str(self.repository['tip']) |
83 | 82 | ||
84 | 83 | ||
85 | def areTherePendingChanges (self): | 84 | def areTherePendingChanges (self): |
86 | # TODO: FIXME: repository.status() does not report 'unknown(?)' files. :( | 85 | # TODO: FIXME: repository.status() does not report 'unknown(?)' files. :( |
87 | return not all(map(lambda fileList: len(fileList) == 0, self.repository.status())) | 86 | return not all(map(lambda fileList: len(fileList) == 0, self.repository.status())) |
88 | 87 | ||
89 | 88 | ||
90 | #=================================================================== | 89 | #=================================================================== |
91 | 90 | ||
91 | |||
92 | class SnapshotRepository(Repository): | 92 | class SnapshotRepository(Repository): |
93 | |||
93 | def revision (self): | 94 | def revision (self): |
94 | return 'SNAPSHOT' | 95 | return 'SNAPSHOT' |
95 | 96 | ||
97 | |||
96 | def areTherePendingChanges (self): | 98 | def areTherePendingChanges (self): |
97 | return False | 99 | return False |