-
Notifications
You must be signed in to change notification settings - Fork 9
/
Commits.py
113 lines (88 loc) · 3.06 KB
/
Commits.py
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
# -*- Mode: python; coding: utf-8 -*-
#
# Cherokee Web Site
#
# Authors:
# Alvaro Lopez Ortega <[email protected]>
#
# Copyright (C) 2001-2011 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
import os
import CTK
import time
import config
CACHE_EXPIRATION = 10 * 60 # 10mins
COMMENT_MAX_SIZE = 60
def run (cmd):
f = os.popen ("cd '%s'; %s" %(config.GIT_CHEROKEE_LOCAL, cmd))
cont = f.read()
try:
f.close()
except:
pass
return cont
#
# Internals
#
def get_commit_list (num):
# Update
run ('git pull')
# Query SVN server
cont = run ('git log --branches --pretty=format:"%an||%ar||%s||%H" -'+str(num))
# Parse
parsed = []
for line in cont.split('\n'):
parts = line.split("||")
if len(parts) != 4:
continue
parsed.append (parts)
return parsed
#
# Widget
#
class Latest_GIT_Commits_Widget (CTK.Box):
def __init__ (self, num=7):
CTK.Box.__init__ (self, {'id': 'latest-commits'})
self += CTK.Box({'class': 'bar3-title'}, CTK.RawHTML('<a href="https://github.com/cherokee/webserver/commits/dev" target="_blank">Latest Commits</a>'))
for commit in get_commit_list (num):
user = commit[0]
date = commit[1]
comment = commit[2]
rev = commit[3]
if len(comment) > COMMENT_MAX_SIZE:
comment = comment[:COMMENT_MAX_SIZE - 3] + "..."
url = "https://github.com/cherokee/webserver/commit/" + rev
content_box = CTK.Box({'class': 'commit'})
date_box = CTK.Box({'class': 'date'})
date_box += CTK.LinkWindow (url, CTK.RawHTML(date), {'title': rev})
content_box += date_box
commit_box = CTK.Box ({'class': 'commit-txt'}, CTK.RawHTML ('%(user)s: %(comment)s'%(locals())))
content_box += commit_box
self += content_box
self += CTK.Box({'class': 'bar3-bottom-link'}, CTK.RawHTML('<a href="https://github.com/cherokee/webserver/commits/dev" target="_blank">View Commits Log »</a>'))
#
# Factory and cache
#
latest_widget = None
latest_widget_expiration = None
def Latest_GIT_Commits():
global latest_widget
global latest_widget_expiration
if not latest_widget or time.time() > latest_widget_expiration:
latest_widget = Latest_GIT_Commits_Widget()
latest_widget_expiration = time.time() + CACHE_EXPIRATION
return latest_widget