summaryrefslogtreecommitdiff
authorJosh <jokajak@gmail.com>2012-06-19 16:04:50 (UTC)
committer Josh <jokajak@gmail.com>2012-06-19 16:04:50 (UTC)
commit28bcbca9846755746541a516f21fe661445a2bae (patch) (unidiff)
treed494b8f28ec4949ecdacd8d6d95f238d62ecd94c
parent59d420a7dab19db63cc3f858492dcf0149e53987 (diff)
downloadclipperz-28bcbca9846755746541a516f21fe661445a2bae.zip
clipperz-28bcbca9846755746541a516f21fe661445a2bae.tar.gz
clipperz-28bcbca9846755746541a516f21fe661445a2bae.tar.bz2
Add a fall-back repository class for SNAPSHOTS
Create a new SnapshotRepository class that returns SNAPSHOT as the version Should let you build if there are any problems with your git repo
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--scripts/builder/repository.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/scripts/builder/repository.py b/scripts/builder/repository.py
index a47e249..7ac2324 100644
--- a/scripts/builder/repository.py
+++ b/scripts/builder/repository.py
@@ -1,88 +1,97 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2# -*- coding: UTF-8 -*- 2# -*- coding: UTF-8 -*-
3 3
4 4
5def repositoryWithPath (path): 5def 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
15 repo = Repo(path) 14 repo = Repo(path)
16 result = GitRepository(repo, path) 15 result = GitRepository(repo, path)
16
17 except ImportError, exception: 17 except ImportError, exception:
18 print "Failed to import git, please install http://gitorious.org/git-python" 18 print "Failed to import git, please install http://gitorious.org/git-python"
19 raise exception 19 raise exception
20 except:
21 result = SnapshotRepository('', path)
20 22
21 23
22 return result 24 return result
23 25
24 26
25#=================================================================== 27#===================================================================
26 28
27 29
28class Repository(object): 30class Repository(object):
29 31
30 def __init__ (self, repository, path): 32 def __init__ (self, repository, path):
31 self.repository = repository 33 self.repository = repository
32 self.path = path 34 self.path = path
33 35
34 36
35 def revision (self): 37 def revision (self):
36 raise NotImplementedError() 38 raise NotImplementedError()
37 39
38 40
39 def areTherePendingChanges (self): 41 def areTherePendingChanges (self):
40 raise NotImplementedError() 42 raise NotImplementedError()
41 43
42 44
43 def version (self): 45 def version (self):
44 result = self.revision() 46 result = self.revision()
45 if self.areTherePendingChanges(): 47 if self.areTherePendingChanges():
46 result = '>>> ' + result + ' <<<' 48 result = '>>> ' + result + ' <<<'
47 49
48 # print "VERSION: " + result 50 # print "VERSION: " + result
49 return result 51 return result
50 52
51 53
52#=================================================================== 54#===================================================================
53 55
54 56
55class GitRepository(Repository): 57class GitRepository(Repository):
56 #http://gitorious.org/git-python 58 #http://gitorious.org/git-python
57 59
58 def revision (self): 60 def revision (self):
59 try: 61 try:
60 return self.repository.head.commit.hexsha 62 return self.repository.head.commit.hexsha
61 except: 63 except:
62 return self.repository.commits()[0].id 64 return self.repository.commits()[0].id
63 65
64 66
65 def areTherePendingChanges (self): 67 def areTherePendingChanges (self):
66 try: 68 try:
67 return self.repository.is_dirty() 69 return self.repository.is_dirty()
68 except TypeError, te: 70 except TypeError, te:
69 return self.repository.is_dirty 71 return self.repository.is_dirty
70 72
71 73
72 74
73#=================================================================== 75#===================================================================
74 76
75 77
76class HgRepository(Repository): 78class HgRepository(Repository):
77 #http://mercurial.selenic.com/wiki/MercurialApi 79 #http://mercurial.selenic.com/wiki/MercurialApi
78 80
79 def revision (self): 81 def revision (self):
80 return 'hg:' + str(self.repository['tip']) 82 return 'hg:' + str(self.repository['tip'])
81 83
82 84
83 def areTherePendingChanges (self): 85 def areTherePendingChanges (self):
84 # TODO: FIXME: repository.status() does not report 'unknown(?)' files. :( 86 # TODO: FIXME: repository.status() does not report 'unknown(?)' files. :(
85 return not all(map(lambda fileList: len(fileList) == 0, self.repository.status())) 87 return not all(map(lambda fileList: len(fileList) == 0, self.repository.status()))
86 88
87 89
88#=================================================================== 90#===================================================================
91
92class SnapshotRepository(Repository):
93 def revision (self):
94 return 'SNAPSHOT'
95
96 def areTherePendingChanges (self):
97 return False