1 from glib
import GError
6 __all__
= ['emblem_names', 'get_emblem_name', 'compare_versions', 'get_icon']
9 vcs
.state
.DIRTY
: 'giterdone-dirty',
10 vcs
.state
.STAGED
: 'giterdone-staged',
11 vcs
.state
.SYNCED
: 'giterdone-synced',
12 vcs
.state
.UNTRACKED
: 'giterdone-untracked'
18 """Loads an icon corresponding to a given file name.
21 name: A file name for an icon in the 'resources' folder.
24 A gtk.gdk.Pixbuf representation of the icon.
27 return gtk
.icon_theme_get_default().load_icon(name
, 20, gtk
.ICON_LOOKUP_USE_BUILTIN
)
29 print 'Giterdone: WARNING could not load icon.'
35 for status_id
, emblem_name
in emblem_names
.iteritems():
36 icon
= load_icon(emblem_name
)
37 if icon
: icons
[status_id
] = icon
39 def get_emblem_name(status_id
):
40 if not status_id
in emblem_names
: return None
41 return emblem_names
[status_id
]
43 def get_icon(status_id
):
44 if icons
== None: init_icons()
45 if not status_id
in icons
: return None
46 return icons
[status_id
]
48 def compare_versions(v1
, v2
):
49 """Like the Java compareTo method, returns the result of comparing to
52 The given versions should be triples of the form (<major>, <minor>,
53 <revision>) (e.g. (1,2,10)). If v1 is newer than v2, a positive number is
54 returned. If v1 and v2 are the same version, 0 is returned. If v2 is newer
55 than v1, a negative number is returned.
57 major_diff
= v1
[0] - v2
[0]
58 if major_diff
!= 0: return major_diff
59 minor_diff
= v1
[1] - v2
[1]
60 if minor_diff
!= 0: return minor_diff