Skip to content

Commit

Permalink
Merge pull request #1 from avdata99/use_unicode_safe
Browse files Browse the repository at this point in the history
Use unicode_safe
  • Loading branch information
tino097 authored Apr 20, 2022
2 parents 2ce1164 + 74f103d commit bced390
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
36 changes: 17 additions & 19 deletions ckanext/harvest/commands/harvester.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from __future__ import print_function

import sys

import six

from ckan import model
from ckan.logic import get_action, ValidationError

from ckantoolkit import CkanCommand

import ckanext.harvest.utils as utils
from ckanext.harvest.logic.schema import unicode_safe


class Harvester(CkanCommand):
Expand Down Expand Up @@ -275,23 +273,23 @@ def initdb(self):
def create_harvest_source(self):

if len(self.args) >= 2:
name = six.text_type(self.args[1])
name = unicode_safe(self.args[1])
else:
print("Please provide a source name")
sys.exit(1)
if len(self.args) >= 3:
url = six.text_type(self.args[2])
url = unicode_safe(self.args[2])
else:
print("Please provide a source URL")
sys.exit(1)
if len(self.args) >= 4:
type = six.text_type(self.args[3])
type = unicode_safe(self.args[3])
else:
print("Please provide a source type")
sys.exit(1)

if len(self.args) >= 5:
title = six.text_type(self.args[4])
title = unicode_safe(self.args[4])
else:
title = None
if len(self.args) >= 6:
Expand All @@ -301,17 +299,17 @@ def create_harvest_source(self):
else:
active = True
if len(self.args) >= 7:
owner_org = six.text_type(self.args[6])
owner_org = unicode_safe(self.args[6])
else:
owner_org = None
if len(self.args) >= 8:
frequency = six.text_type(self.args[7])
frequency = unicode_safe(self.args[7])
if not frequency:
frequency = "MANUAL"
else:
frequency = "MANUAL"
if len(self.args) >= 9:
source_config = six.text_type(self.args[8])
source_config = unicode_safe(self.args[8])
else:
source_config = None
try:
Expand All @@ -329,30 +327,30 @@ def clear_harvest_source_history(self):
keep_current = bool(self.options.keep_current)
source_id = None
if len(self.args) >= 2:
source_id = six.text_type(self.args[1])
source_id = unicode_safe(self.args[1])

print(utils.clear_harvest_source_history(source_id, keep_current))

def show_harvest_source(self):

if len(self.args) >= 2:
source_id_or_name = six.text_type(self.args[1])
source_id_or_name = unicode_safe(self.args[1])
else:
print("Please provide a source name")
sys.exit(1)
print(utils.show_harvest_source(source_id_or_name))

def remove_harvest_source(self):
if len(self.args) >= 2:
source_id_or_name = six.text_type(self.args[1])
source_id_or_name = unicode_safe(self.args[1])
else:
print("Please provide a source id")
sys.exit(1)
utils.remove_harvest_source(source_id_or_name)

def clear_harvest_source(self):
if len(self.args) >= 2:
source_id_or_name = six.text_type(self.args[1])
source_id_or_name = unicode_safe(self.args[1])
else:
print("Please provide a source id")
sys.exit(1)
Expand All @@ -368,7 +366,7 @@ def list_harvest_sources(self):

def create_harvest_job(self):
if len(self.args) >= 2:
source_id_or_name = six.text_type(self.args[1])
source_id_or_name = unicode_safe(self.args[1])
else:
print("Please provide a source id")
sys.exit(1)
Expand All @@ -379,7 +377,7 @@ def list_harvest_jobs(self):

def job_abort(self):
if len(self.args) >= 2:
job_or_source_id_or_name = six.text_type(self.args[1])
job_or_source_id_or_name = unicode_safe(self.args[1])
else:
print("Please provide a job id or source name/id")
sys.exit(1)
Expand All @@ -394,7 +392,7 @@ def run_test_harvest(self):
if len(self.args) >= 2:
if len(self.args) >= 3 and self.args[2].startswith('force-import='):
force_import = self.args[2].split('=')[-1]
source_id_or_name = six.text_type(self.args[1])
source_id_or_name = unicode_safe(self.args[1])
else:
print("Please provide a source id")
sys.exit(1)
Expand All @@ -404,7 +402,7 @@ def run_test_harvest(self):
def import_stage(self):

if len(self.args) >= 2:
source_id_or_name = six.text_type(self.args[1])
source_id_or_name = unicode_safe(self.args[1])
context = {
"model": model,
"session": model.Session,
Expand Down Expand Up @@ -440,7 +438,7 @@ def clean_harvest_log(self):
def abort_failed_jobs(self):
job_life_span = False
if len(self.args) >= 2:
job_life_span = six.text_type(self.args[1])
job_life_span = unicode_safe(self.args[1])

utils.abort_failed_jobs(
job_life_span,
Expand Down
7 changes: 3 additions & 4 deletions ckanext/harvest/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
from logging import getLogger

from six import string_types, text_type
from six import string_types
from collections import OrderedDict

from ckan import logic
Expand Down Expand Up @@ -232,11 +232,10 @@ def create_package_schema(self):
Returns the schema for mapping package data from a form to a format
suitable for the database.
'''
from ckanext.harvest.logic.schema import harvest_source_create_package_schema
from ckanext.harvest.logic.schema import harvest_source_create_package_schema, unicode_safe
schema = harvest_source_create_package_schema()
if self.startup:
schema['id'] = [text_type]

schema['id'] = [unicode_safe]
return schema

def update_package_schema(self):
Expand Down

0 comments on commit bced390

Please sign in to comment.