More tidy

This commit is contained in:
Simeon Warner 2020-12-10 09:16:10 -05:00
parent a15b4c50ce
commit 30ab56b14a
7 changed files with 20 additions and 26 deletions

View File

@ -5,14 +5,12 @@ python:
- "3.6"
- "3.7"
install:
- pip install requests
- pip install python-dateutil
- pip install coveralls pycodestyle pep257 restructuredtext_lint testfixtures
- python setup.py install
script:
- python setup.py test
- pycodestyle --ignore=E501,W503 resync tests bin/resync bin/resync-explorer
- pep257 resync tests bin/resync bin/resync-explorer
- pycodestyle --ignore=E501,W503 resync tests resync.py resync-explorer.py
- pep257 resync tests resync.py resync-explorer.py
- rst-lint README
- coverage run --source=resync setup.py test
after_success:

View File

@ -1,8 +1,7 @@
#!/usr/bin/env python
"""
resync-explorer: The ResourceSync explorer
"""resync-explorer: The ResourceSync explorer.
Copyright 2012-2017 Simeon Warner
Copyright 2012-2020 Simeon Warner
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -29,7 +28,7 @@ DEFAULT_LOGFILE = 'resync-explorer.log'
def main():
"""Main function to implement command line script."""
if (sys.version_info < (2, 7)):
sys.exit("This program requires python version 2.7 or later")

View File

@ -1,8 +1,7 @@
#!/usr/bin/env python
"""
resync: The ResourceSync command line client
"""resync: The ResourceSync command line client.
Copyright 2012-2017 Simeon Warner
Copyright 2012-2020 Simeon Warner
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -28,7 +27,7 @@ DEFAULT_LOGFILE = 'resync-client.log'
def main():
"""Main function to implement command line script."""
if (sys.version_info < (2, 7)):
sys.exit("This program requires python version 2.7 or later")

View File

@ -395,8 +395,8 @@ class Client(object):
if (not change_list_uri):
uauth_sm = UrlAuthority(self.sitemap)
for resource in src_change_list:
if (not uauth_cs.has_authority_over(resource.uri) and
(change_list_uri or not uauth_sm.has_authority_over(resource.uri))):
if (not uauth_cs.has_authority_over(resource.uri)
and (change_list_uri or not uauth_sm.has_authority_over(resource.uri))):
raise ClientFatalError(
"Aborting as change list (%s) mentions resource at a location it does not have authority over (%s), override with --noauth" %
(change_list, resource.uri))
@ -586,8 +586,8 @@ class Client(object):
"""
num_deleted = 0
uri = resource.uri
if (resource.timestamp is not None and
resource.timestamp > self.last_timestamp):
if (resource.timestamp is not None
and resource.timestamp > self.last_timestamp):
self.last_timestamp = resource.timestamp
if (allow_deletion):
if (self.dryrun):

View File

@ -96,7 +96,7 @@ class Dump(object):
# without this installed
try:
from warc import WARCFile, WARCHeader, WARCRecord
except:
except ImportError:
raise DumpError("Failed to load WARC library")
wf = WARCFile(dumpfile, mode="w", compress=self.compress)
# Add all files in the resources
@ -175,8 +175,7 @@ class Dump(object):
manifest.add(resource)
manifest_size += resource.length
manifest_files += 1
if (manifest_size >= self.max_size or
manifest_files >= self.max_files):
if (manifest_size >= self.max_size or manifest_files >= self.max_files):
yield(manifest)
# Need to start a new manifest
manifest = self.manifest_class()

View File

@ -288,8 +288,7 @@ class Explorer(Client):
'lastmod', 'content-type', 'etag']:
if header in response.headers:
check_str = ''
if (check_headers is not None and
header in check_headers):
if (check_headers is not None and header in check_headers):
if (response.headers[header] == check_headers[header]):
check_str = ' MATCHES EXPECTED VALUE'
else:

View File

@ -150,8 +150,8 @@ class ListBaseWithIndex(ListBase):
else:
# The individual sitemaps should be at a URL (scheme/server/path)
# that the sitemapindex URL can speak authoritatively about
if (self.check_url_authority and
not UrlAuthority(sitemapindex_uri).has_authority_over(sitemap_uri)):
if (self.check_url_authority
and not UrlAuthority(sitemapindex_uri).has_authority_over(sitemap_uri)):
raise ListBaseIndexError(
"The sitemapindex (%s) refers to sitemap at a location it does not have authority over (%s)" %
(sitemapindex_uri, sitemap_uri))
@ -187,8 +187,8 @@ class ListBaseWithIndex(ListBase):
In the case that no len() is available for self.resources then
then self.count must be set beforehand to avoid an exception.
"""
if (self.max_sitemap_entries is None or
len(self) <= self.max_sitemap_entries):
if (self.max_sitemap_entries is None
or len(self) <= self.max_sitemap_entries):
return(False)
return(int(math.ceil(len(self) / float(self.max_sitemap_entries))))
@ -409,7 +409,7 @@ class ListBaseWithIndex(ListBase):
Test is to see whether have either an explicit file: URI or whether
there is no scheme name.
"""
return(re.match('file:', uri) or not re.match('\w{3,4}:', uri))
return(re.match(r'file:', uri) or not re.match(r'\w{3,4}:', uri))
class ListBaseIndexError(Exception):