-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDistro.py
More file actions
175 lines (132 loc) · 4.13 KB
/
Distro.py
File metadata and controls
175 lines (132 loc) · 4.13 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# -*- Mode: python; coding: utf-8 -*-
#
# Cherokee Web Site
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# 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 re
import CTK
import gzip
import time
import config
CACHE_EXPIRATION = 2 * 60 * 60
#
# Index file
#
def parse_distro_index():
distro_root = os.path.join (config.DOWNLOADS_LOCAL, "distribution")
distro_index = os.path.join (distro_root, "index.py.gz")
# Read
f = gzip.open (distro_index, 'rb')
content = f.read()
f.close()
# Parse
return CTK.util.data_eval (content)
latest_info = None
latest_info_expiration = None
def Distro_Info():
global latest_info
global latest_info_expiration
if not latest_info or time.time() > latest_info_expiration:
latest_info = parse_distro_index()
latest_info_expiration = time.time() + CACHE_EXPIRATION
return latest_info
#
# Utils
#
def get_authors():
# Collect Authors
info = Distro_Info()
pkgs = info.get('packages', {})
names = {}
for pkg_name in pkgs:
pkg = pkgs[pkg_name]
maintainer = pkg.get('maintainer', {})
name = maintainer.get('name')
if name and not names.keys():
names[name] = maintainer.get('email')
# {name : email}
return names
def get_orphans():
# Collect Orphan packages
info = Distro_Info()
pkgs = info.get('packages', {})
orphans = []
for pkg_name in pkgs:
pkg = pkgs[pkg_name]
maintainer = pkg.get('maintainer', {})
name = maintainer.get('name')
if not name:
orphans.append (pkg_name)
# [ pkg_name, ]
return orphans
#
# Widgets
#
class Orphans_List (CTK.Box):
def __init__ (self):
CTK.Box.__init__ (self, {'id': 'orphans_list'})
orphans = get_orphans()
# Build Widget
l = CTK.List()
for pkg_name in orphans:
entry = CTK.Box()
entry += CTK.RawHTML (pkg_name)
l += entry
self += l
class Authors_List (CTK.Box):
def __init__ (self):
CTK.Box.__init__ (self, {'id': 'authors_list'})
names = get_authors()
# Build Widget
l = CTK.List()
for name in names:
entry = CTK.Box()
entry += CTK.RawHTML (name)
entry += CTK.RawHTML (names[name] or '')
l += entry
self += l
class Apps_List (CTK.Box):
def __init__ (self):
CTK.Box.__init__ (self, {'id': 'apps_list'})
info = Distro_Info()
pkgs = info.get('packages', {})
l = CTK.List()
self += l
for pkg_name in pkgs:
pkg = pkgs[pkg_name]
# Icon
icon_url = os.path.join (config.DOWNLOADS_WEB, 'distribution', pkg_name, 'icons',
pkg.get('software',{}).get('icon_small',''))
image = CTK.Image ({'src': icon_url})
box = CTK.Box ({'class': 'app_entry'})
box += CTK.Box ({'class': 'title'}, CTK.RawHTML (pkg.get('software',{}).get('name','')))
box += CTK.Box ({'class': 'icon'}, image)
l+= box
latest_auth_wid = None
latest_auth_wid_expiration = None
def Latest_Tweets():
global latest_auth_wid
global latest_auth_wid_expiration
if not latest_auth_wid or time.time() > latest_widget_expiration:
latest_auth_wid = Authors_List()
latest_auth_wid_expiration = time.time() + CACHE_EXPIRATION
return latest_auth_wid