23
23
log .fatal ("No token found, cannot access the GitHub API" )
24
24
except ValueError :
25
25
log .fatal ("Token file cannot be properly read, should be of the form username:token" )
26
- finally :
27
- sys .exit (- 1 )
26
+ except :
27
+ log .exception ("auth execption:" )
28
+ # sys.exit(-1)
28
29
29
30
user_cache = {}
30
31
@@ -94,6 +95,8 @@ def rate_limit(resp):
94
95
ts = datetime .fromtimestamp (reset )
95
96
delay = (ts - datetime .now ()).total_seconds ()
96
97
log .info ("Hit rate limit. Have to wait for %d seconds" , delay )
98
+ if delay < 0 : # time drift
99
+ delay = 2
97
100
time .sleep (delay )
98
101
99
102
@@ -114,40 +117,46 @@ def check_repo(repo):
114
117
avatar_url = get_avatar_url (repo )
115
118
116
119
for plug in plug_items :
117
- plugfile_resp = requests .get ('https://raw.githubusercontent.com/%s/master/%s' % (repo , plug [" path" ]))
120
+ plugfile_resp = requests .get ('https://raw.githubusercontent.com/%s/master/%s' % (repo , plug [' path' ]))
118
121
log .debug ('Found a plugin:' )
119
122
log .debug ('Repo: %s' , repo )
120
123
log .debug ('File: %s' , plug ['path' ])
121
124
parser = configparser .ConfigParser ()
122
- parser .read_string (plugfile_resp .text )
123
- name = parser ['Core' ]['Name' ]
124
- log .debug ('Name: %s' , name )
125
-
126
- if 'Documentation' in parser :
127
- doc = parser ['Documentation' ]['Description' ]
128
- log .debug ('Documentation: %s' , doc )
129
- else :
130
- doc = ''
131
-
132
- if 'Python' in parser :
133
- python = parser ['Python' ]['Version' ]
134
- log .debug ('Python Version: %s' , python )
135
- else :
136
- python = '2'
137
-
138
- plugin = {
139
- 'path' : plug ['path' ],
140
- 'repo' : 'https://github.com/{0}' .format (repo ),
141
- 'documentation' : doc ,
142
- 'name' : name ,
143
- 'python' : python ,
144
- 'avatar_url' : avatar_url ,
145
- }
146
-
147
- repo_entry = plugins .get (repo , {})
148
- repo_entry [name ] = plugin
149
- plugins [repo ] = repo_entry
150
- log .debug ('Catalog added plugin %s.' , plugin ['name' ])
125
+ try :
126
+ parser .read_string (plugfile_resp .text )
127
+
128
+ name = parser ['Core' ]['Name' ]
129
+ log .debug ('Name: %s' , name )
130
+
131
+ if 'Documentation' in parser and 'Description' in parser ['Documentation' ]:
132
+ doc = parser ['Documentation' ]['Description' ]
133
+ log .debug ('Documentation: %s' , doc )
134
+ else :
135
+ doc = ''
136
+
137
+ if 'Python' in parser :
138
+ python = parser ['Python' ]['Version' ]
139
+ log .debug ('Python Version: %s' , python )
140
+ else :
141
+ python = '2'
142
+
143
+ plugin = {
144
+ 'path' : plug ['path' ],
145
+ 'repo' : 'https://github.com/{0}' .format (repo ),
146
+ 'documentation' : doc ,
147
+ 'name' : name ,
148
+ 'python' : python ,
149
+ 'avatar_url' : avatar_url ,
150
+ }
151
+
152
+ repo_entry = plugins .get (repo , {})
153
+ repo_entry [name ] = plugin
154
+ plugins [repo ] = repo_entry
155
+ log .debug ('Catalog added plugin %s.' , plugin ['name' ])
156
+ except :
157
+ log .error ('Invalid syntax in %s, skipping... ' % plug ['path' ])
158
+ continue
159
+
151
160
rate_limit (plugfile_resp )
152
161
153
162
save_plugins ()
@@ -165,6 +174,10 @@ def find_plugins():
165
174
log .debug ("Repo reqs before ratelimit %s/%s" % (
166
175
repo_resp .headers ['X-RateLimit-Remaining' ],
167
176
repo_resp .headers ['X-RateLimit-Limit' ]))
177
+ if 'message' in repo_json and repo_json ['message' ].startswith ('API rate limit exceeded for' ):
178
+ log .error ('API rate limit hit anyway ... wait for 30s' )
179
+ time .sleep (30 )
180
+ continue
168
181
items = repo_json ['items' ]
169
182
170
183
for i , item in enumerate (items ):
0 commit comments