1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf8 -*- |
3
|
|
|
# |
4
|
|
|
# versions.py : checks releases and versions of programs through RSS |
5
|
|
|
# or Atom feeds and tells you |
6
|
|
|
# |
7
|
|
|
# (C) Copyright 2016 - 2018 Olivier Delhomme |
8
|
|
|
# e-mail : [email protected] |
9
|
|
|
# |
10
|
|
|
# This program is free software; you can redistribute it and/or modify |
11
|
|
|
# it under the terms of the GNU General Public License as published by |
12
|
|
|
# the Free Software Foundation; either version 3, or (at your option) |
13
|
|
|
# any later version. |
14
|
|
|
# |
15
|
|
|
# This program is distributed in the hope that it will be useful, |
16
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
# GNU General Public License for more details. |
19
|
|
|
# |
20
|
|
|
# You should have received a copy of the GNU General Public License |
21
|
|
|
# along with this program; if not, write to the Free Software Foundation, |
22
|
|
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23
|
|
|
# |
24
|
1 |
|
import codecs |
25
|
1 |
|
import sys |
26
|
1 |
|
import locale |
27
|
1 |
|
import os |
28
|
1 |
|
import doctest |
29
|
1 |
|
import configuration |
30
|
1 |
|
import caches |
31
|
1 |
|
import common |
32
|
1 |
|
import byproject |
33
|
1 |
|
import bylist |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
""" |
37
|
|
|
This program checks projects versions through RSS and Atom feeds and |
38
|
|
|
should only print those with new release version. |
39
|
|
|
|
40
|
|
|
It implements checking for projects in github.com and freshcode.club. |
41
|
|
|
Projects must be added to a YAML file (named by default |
42
|
|
|
~/.config/versions/versions.yaml). One can use --file=FILENAME option |
43
|
|
|
to specify an alternative YAML file. version.yaml is included as an |
44
|
|
|
example in this project. |
45
|
|
|
|
46
|
|
|
Versions uses and produces text files. Those files are cache files |
47
|
|
|
written into ~/.local/versions directory. "*.cache" are cache files |
48
|
|
|
containing the project list and their associated version (the latest). |
49
|
|
|
"*.feed" are information feed cache files containing on only one line |
50
|
|
|
the latest parsed post of the feed. |
51
|
|
|
""" |
52
|
|
|
|
53
|
|
|
|
54
|
1 |
|
def check_versions(versions_conf): |
55
|
|
|
""" |
56
|
|
|
Checks versions by parsing online feeds. |
57
|
|
|
""" |
58
|
|
|
|
59
|
|
|
# Checks projects from by project sites such as github and sourceforge |
60
|
1 |
|
byproject_site_list = versions_conf.extract_site_list('byproject') |
61
|
1 |
|
byproject.check_versions(versions_conf, byproject_site_list) |
62
|
|
|
|
63
|
|
|
# Checks projects from 'list' tupe sites such as freshcode.club |
64
|
1 |
|
list_site_list = versions_conf.extract_site_list('list') |
65
|
1 |
|
bylist.check_versions(versions_conf, list_site_list) |
66
|
|
|
# End of check_versions() function |
67
|
|
|
|
68
|
|
|
|
69
|
1 |
|
def print_cache_or_check_versions(versions_conf): |
70
|
|
|
""" |
71
|
|
|
Decide to pretty print projects and their associated version that |
72
|
|
|
are already in the cache or to check versions of that projects upon |
73
|
|
|
selections made at the command line |
74
|
|
|
""" |
75
|
|
|
|
76
|
1 |
|
common.print_debug(versions_conf.options.debug, u'Loading yaml config file') |
77
|
1 |
|
versions_conf.load_yaml_from_config_file(versions_conf.config_filename) |
78
|
|
|
|
79
|
1 |
|
if versions_conf.options.list_cache is True: |
80
|
|
|
# Pretty prints all caches. |
81
|
1 |
|
cache_list = versions_conf.make_site_cache_list_name() |
82
|
1 |
|
caches.print_versions_from_cache(versions_conf.local_dir, cache_list) |
83
|
|
|
|
84
|
|
|
else: |
85
|
|
|
# Checks version from online feeds |
86
|
1 |
|
check_versions(versions_conf) |
87
|
|
|
|
88
|
|
|
# End of print_list_or_check_versions() function. |
89
|
|
|
|
90
|
|
|
|
91
|
1 |
|
def testmodule(name): |
92
|
|
|
""" |
93
|
|
|
Runs doctests in the module called 'name' |
94
|
|
|
""" |
95
|
|
|
|
96
|
1 |
|
print(u'{} {} {}'.format(u'»»»»»»»»»»»»»»»» Testing module:', name, u'««««««««««««««««')) |
97
|
1 |
|
mod = __import__(name) |
98
|
1 |
|
doctest.testmod(mod, verbose=True) |
99
|
1 |
|
print(u'{}'.format('End.\n')) |
100
|
|
|
|
101
|
|
|
# End of testmodule() function. |
102
|
|
|
|
103
|
|
|
|
104
|
1 |
|
def main(): |
105
|
|
|
""" |
106
|
|
|
This is the where the program begins |
107
|
|
|
""" |
108
|
|
|
|
109
|
1 |
|
if sys.version_info[0] == 2: |
110
|
|
|
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout) |
111
|
|
|
|
112
|
1 |
|
versions_conf = configuration.Conf() # Configuration options |
113
|
|
|
|
114
|
1 |
|
if versions_conf.options.debug: |
115
|
1 |
|
module_list = ['__main__', 'common', 'caches', 'configuration', 'byproject', 'bylist'] |
116
|
1 |
|
for module_name in module_list: |
117
|
1 |
|
testmodule(module_name) |
118
|
|
|
|
119
|
1 |
|
if os.path.isfile(versions_conf.config_filename): |
120
|
1 |
|
print_cache_or_check_versions(versions_conf) |
121
|
|
|
|
122
|
|
|
else: |
123
|
1 |
|
print(u'Error: file {} does not exist'.format(versions_conf.config_filename)) |
124
|
|
|
|
125
|
|
|
# End of main() function |
126
|
|
|
|
127
|
|
|
|
128
|
1 |
|
if __name__ == "__main__": |
129
|
|
|
main() |
130
|
|
|
|