GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

versions.bylist   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 208
Duplicated Lines 0 %

Test Coverage

Coverage 95.71%

Importance

Changes 0
Metric Value
eloc 71
dl 0
loc 208
ccs 67
cts 70
cp 0.9571
rs 10
c 0
b 0
f 0
wmc 20

8 Functions

Rating   Name   Duplication   Size   Complexity  
A cut_title_in_project_version() 0 27 3
A cut_title_with_default_method() 0 17 2
A split_multiproject_title_into_list() 0 12 2
A lower_list_of_strings() 0 10 1
A cut_title_with_regex_method() 0 22 2
A check_and_update_feed() 0 27 4
A check_versions() 0 12 2
A check_versions_for_list_sites() 0 24 4
1
#!/usr/bin/env python
2
# -*- coding: utf8 -*-
3
#
4
#  bylist.py : related to sites that gives one RSS/Atom feed for
5
#              all the projects (such as freshcode.club)
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 re
25 1
import caches
26 1
import common
27
28
29 1
def cut_title_with_default_method(title):
30
    """
31
    Cuts title with a default method and a fallback
32
    >>> cut_title_with_default_method('versions 1.3.2')
33
    ('versions', '1.3.2')
34
    >>> cut_title_with_default_method('no_version_project')
35
    ('no_version_project', '')
36
    """
37
38 1
    try:
39 1
        (project, version) = title.strip().split(' ', 1)
40
41 1
    except ValueError:
42 1
        project = title.strip()
43 1
        version = ''
44
45 1
    return (project, version)
46
47
# End of cut_title_with_default_method() function
48
49
50 1
def cut_title_with_regex_method(title, regex):
51
    """
52
    Cuts title using a regex. If it does not success
53
    fallback to default.
54
    >>> cut_title_with_regex_method('versions 1.3.2', '([\w]+)\s([\d\.]+)')
55
    ('versions', '1.3.2', False)
56
    >>> cut_title_with_regex_method('versions 1.3.2', '([\w]+)notgood\s([\d\.]+)')
57
    ('', '', True)
58
    """
59
60 1
    default = False
61 1
    project = ''
62 1
    version = ''
63
64 1
    res = re.match(regex, title)
65 1
    if res:
66 1
        project = res.group(1)
67 1
        version = res.group(2)
68
    else:
69 1
        default = True
70
71 1
    return (project, version, default)
72
73
# End of cut_title_with_regex_method() function
74
75
76 1
def cut_title_in_project_version(title, regex):
77
    """
78
    Cuts the title into a tuple (project, version) where possible with a regex
79
    or if there is no regex or the regex did not match cuts the title with a
80
    default method
81
    >>> cut_title_in_project_version('versions 1.3.2', None)
82
    ('versions', '1.3.2')
83
    >>> cut_title_in_project_version('no_version_project', None)
84
    ('no_version_project', '')
85
    >>> cut_title_in_project_version('versions 1.3.2', '([\w]+)badregex\s([\d\.]+)')
86
    ('versions', '1.3.2')
87
    >>> cut_title_in_project_version('versions 1.3.2', '([\w]+)\s([\d\.i\-rcbetaRCBETA]+)')
88
    ('versions', '1.3.2')
89
    """
90 1
    default = False
91 1
    project = ''
92 1
    version = ''
93
94 1
    if regex is not None:
95 1
        (project, version, default) = cut_title_with_regex_method(title, regex)
96
    else:
97 1
        default = True
98
99 1
    if default:
100 1
        (project, version) = cut_title_with_default_method(title)
101
102 1
    return (project, version)
103
104
# End of cut_title_in_project_version() function
105
106
107 1
def lower_list_of_strings(project_list):
108
    """
109
    Lowers every string in the list to ease sorting and comparisons
110
    >>> lower_list_of_strings(['TEST', 'LoweRed'])
111
    ['test', 'lowered']
112
    """
113
114 1
    project_list_low = [project.lower() for project in project_list]
115
116 1
    return project_list_low
117
118
# End of lower_list_of_strings() function
119
120
121 1
def split_multiproject_title_into_list(title, multiproject):
122
    """
123
    Splits title into a list of projects according to multiproject being
124
    a list of separators
125
    """
126
127 1
    if multiproject is not None:
128
        titles = re.split(multiproject, title)
129
    else:
130 1
        titles = [title]
131
132 1
    return titles
133
134
# End of split_multiproject_title_into_list() function
135
136
137 1
def check_and_update_feed(feed_list, project_list, cache, debug, regex, multiproject):
138
    """
139
    Checks every feed entry in the list against project list cache and
140
    then updates the dictionary then writes the cache file to the disk.
141
     - feed_list    is a list of feed (from feedparser module)
142
     - project_list is the list of project as read from the yaml
143
                    configuration file
144
     - cache is an initialized instance of FileCache
145
    """
146
147
    # Lowers the list before searching in it
148 1
    project_list_low = lower_list_of_strings(project_list)
149
150
    # Checking every feed entry that are newer than the last check
151
    # and updates the dictionary accordingly
152 1
    for entry in feed_list:
153
154 1
        titles = split_multiproject_title_into_list(entry.title, multiproject)
155
156 1
        for title in titles:
157 1
            (project, version) = cut_title_in_project_version(title, regex)
158 1
            common.print_debug(debug, u'\tChecking {0:16}: {1}'.format(project, version))
159 1
            if project.lower() in project_list_low:
160
                cache.print_if_newest_version(project, version, debug)
161
                cache.update_cache_dict(project, version, debug)
162
163 1
    cache.write_cache_file()
164
165
# End of check_and_update_feed() function
166
167
168 1
def check_versions_for_list_sites(feed_project_list, url, cache_filename, feed_filename, local_dir, debug, regex, multiproject):
169
    """
170
    Checks projects of 'list' type sites such as freshcode's web site's RSS
171
    """
172
173 1
    freshcode_cache = caches.FileCache(local_dir, cache_filename)
174
175 1
    feed_info = caches.FeedCache(local_dir, feed_filename)
176 1
    feed_info.read_cache_feed()
177
178 1
    feed = common.get_feed_entries_from_url(url)
179
180 1
    if feed is not None:
181 1
        common.print_debug(debug, u'\tFound {} entries'.format(len(feed.entries)))
182 1
        feed_list = common.make_list_of_newer_feeds(feed, feed_info, debug)
183 1
        common.print_debug(debug, u'\tFound {} new entries (relative to {})'.format(len(feed_list), feed_info.date_minutes))
184
185 1
        check_and_update_feed(feed_list, feed_project_list, freshcode_cache, debug, regex, multiproject)
186
187
        # Updating feed_info with the latest parsed feed entry date
188 1
        if feed.entries is not None and len(feed.entries) >= 1:
189 1
            feed_info.update_cache_feed(feed.entries[0].published_parsed)
190
191 1
    feed_info.write_cache_feed()
192
193
# End of check_versions_for_list_sites() function
194
195
196 1
def check_versions(versions_conf, list_site_list):
197
    """
198
    Checks version by checking each project's feed.
199
    """
200
201 1
    for site_name in list_site_list:
202 1
        common.print_debug(versions_conf.options.debug, u'Checking {} updates'.format(site_name))
203 1
        (project_list, project_url, cache_filename, project_entry) = versions_conf.get_infos_for_site(site_name)
204 1
        regex = versions_conf.extract_regex_from_site(site_name)
205 1
        multiproject = versions_conf.extract_multiproject_from_site(site_name)
206 1
        feed_filename = u'{}.feed'.format(site_name)
207 1
        check_versions_for_list_sites(project_list, project_url, cache_filename, feed_filename, versions_conf.local_dir, versions_conf.options.debug, regex, multiproject)
208
209
# End of check_versions() function
210