Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Fix Flake8 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Oct 3, 2019
1 parent 5771897 commit 3793480
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions ckanext/harvest/controllers/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def show_object(self, id, ref_type='object'):
else:
abort(404, _('No content found'))
try:
etree.fromstring(re.sub('<\?xml(.*)\?>', '', content))
etree.fromstring(re.sub(r'<\?xml(.*)\?>', '', content))
except UnicodeEncodeError:
etree.fromstring(
re.sub('<\?xml(.*)\?>', '', content.encode('utf-8'))
re.sub(r'<\?xml(.*)\?>', '', content.encode('utf-8'))
)
response.content_type = 'application/xml; charset=utf-8'
if '<?xml' not in content.split('\n')[0]:
Expand Down
1 change: 0 additions & 1 deletion ckanext/harvest/harvesters/ckanharvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def get_extra(key, package_dict):
# key.
resource.pop('revision_id', None)


package_dict = self.modify_package_dict(package_dict, harvest_object)

result = self._create_or_update_package(
Expand Down
35 changes: 18 additions & 17 deletions ckanext/harvest/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ def get_connection_redis():
if not config.get('ckan.harvest.mq.hostname') and config.get('ckan.redis.url'):
return redis.StrictRedis.from_url(config['ckan.redis.url'])
else:
return redis.StrictRedis(host=config.get('ckan.harvest.mq.hostname', HOSTNAME),
port=int(config.get('ckan.harvest.mq.port', REDIS_PORT)),
password=config.get('ckan.harvest.mq.password', None),
db=int(config.get('ckan.harvest.mq.redis_db', REDIS_DB)))
return redis.StrictRedis(
host=config.get('ckan.harvest.mq.hostname', HOSTNAME),
port=int(config.get('ckan.harvest.mq.port', REDIS_PORT)),
password=config.get('ckan.harvest.mq.password', None),
db=int(config.get('ckan.harvest.mq.redis_db', REDIS_DB)))


def get_gather_queue_name():
Expand All @@ -87,12 +88,12 @@ def get_fetch_queue_name():

def get_gather_routing_key():
return 'ckanext-harvest:{0}:harvest_job_id'.format(
config.get('ckan.site_id', 'default'))
config.get('ckan.site_id', 'default'))


def get_fetch_routing_key():
return 'ckanext-harvest:{0}:harvest_object_id'.format(
config.get('ckan.site_id', 'default'))
config.get('ckan.site_id', 'default'))


def purge_queues():
Expand Down Expand Up @@ -173,13 +174,14 @@ def __init__(self, connection, channel, exchange, routing_key):
self.routing_key = routing_key

def send(self, body, **kw):
return self.channel.basic_publish(self.exchange,
self.routing_key,
json.dumps(body),
properties=pika.BasicProperties(
delivery_mode=2, # make message persistent
),
**kw)
return self.channel.basic_publish(
self.exchange,
self.routing_key,
json.dumps(body),
properties=pika.BasicProperties(
delivery_mode=2, # make message persistent
),
**kw)

def close(self):
self.connection.close()
Expand Down Expand Up @@ -295,6 +297,7 @@ def get_consumer(queue_name, routing_key):


def gather_callback(channel, method, header, body):

try:
id = json.loads(body)['harvest_job_id']
log.debug('Received harvest job id: %s' % id)
Expand Down Expand Up @@ -326,7 +329,6 @@ def gather_callback(channel, method, header, body):
# the Harvester interface, only if the source type
# matches
harvester = get_harvester(job.source.type)

if harvester:
try:
harvest_object_ids = gather_stage(harvester, job)
Expand All @@ -347,7 +349,7 @@ def gather_callback(channel, method, header, body):
return False

log.debug('Received from plugin gather_stage: {0} objects (first: {1} last: {2})'.format(
len(harvest_object_ids), harvest_object_ids[:1], harvest_object_ids[-1:]))
len(harvest_object_ids), harvest_object_ids[:1], harvest_object_ids[-1:]))
for id in harvest_object_ids:
# Send the id to the fetch queue
publisher.send({'harvest_object_id': id})
Expand All @@ -366,7 +368,6 @@ def gather_callback(channel, method, header, body):
log.info('Marking job as finished due to error: %s %s',
job.source.url, job.id)


model.Session.remove()
publisher.close()
channel.basic_ack(method.delivery_tag)
Expand Down Expand Up @@ -465,7 +466,7 @@ def fetch_and_import_stages(harvester, obj):
obj.import_finished = datetime.datetime.utcnow()
if success_import:
obj.state = "COMPLETE"
if success_import is 'unchanged':
if success_import == 'unchanged':
obj.report_status = 'not modified'
obj.save()
return
Expand Down
4 changes: 2 additions & 2 deletions ckanext/harvest/tests/harvesters/mock_ckan.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def do_GET(self):

# The API version is recorded and then removed from the path
api_version = None
version_match = re.match('^/api/(\d)', self.path)
version_match = re.match(r'^/api/(\d)', self.path)
if version_match:
api_version = int(version_match.groups()[0])
self.path = re.sub('^/api/(\d)/', '/api/', self.path)
self.path = re.sub(r'^/api/(\d)/', '/api/', self.path)

if self.path == '/api/rest/package':
if api_version == 2:
Expand Down
4 changes: 2 additions & 2 deletions ckanext/harvest/tests/harvesters/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_random_config(self):
factories.Dataset(name='trees')
new_name = HarvesterBase._gen_new_name('Trees')

assert re.match('trees[\da-f]{5}', new_name)
assert re.match(r'trees[\da-f]{5}', new_name)

@patch.dict('ckanext.harvest.harvesters.base.config',
{'ckanext.harvest.default_dataset_name_append': 'random-hex'})
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_existing_dataset_appending_hex(self):
factories.Dataset(name='trees')
name = _ensure_name_is_unique('trees', append_type='random-hex')
# e.g. 'trees0b53f'
assert re.match('trees[\da-f]{5}', name)
assert re.match(r'trees[\da-f]{5}', name)


# taken from ckan/tests/lib/test_munge.py
Expand Down

0 comments on commit 3793480

Please sign in to comment.