本文整理汇总了Python中b2handle.clientcredentials.PIDClientCredentials类的典型用法代码示例。如果您正苦于以下问题:Python PIDClientCredentials类的具体用法?Python PIDClientCredentials怎么用?Python PIDClientCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PIDClientCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_config_from_init
def test_config_from_init(self):
"""Test credentials instantiation from JSON file, with config."""
inst = PIDClientCredentials(handle_server_url=self.url,
username=self.user,
password=self.randompassword,
foo='bar',
bar='baz')
self.assertEqual(inst.get_config()['foo'], 'bar',
'Config not the same as in json file.')
self.assertEqual(inst.get_config()['bar'], 'baz',
'Config not the same as in json file.')
示例2: read
def read(args):
"""perform read action"""
try:
# load credentials
credentials = PIDClientCredentials.load_from_JSON(args.credpath)
except CredentialsFormatError:
sys.stdout.write('error')
return
except HandleSyntaxError:
sys.stdout.write('error')
return
# retrieve and set extra values
extra_config = {}
try:
# setup connection to handle server
client = EUDATHandleClient.instantiate_with_credentials(
credentials,
**extra_config)
except HandleNotFoundException:
sys.stdout.write('error')
return
if args.key is None:
result = read_execution(client, args.handle)
else:
result = read_execution(client, args.handle, args.key)
sys.stdout.write(result)
示例3: create
def create(args):
"""perform create action"""
try:
# load credentials
credentials = PIDClientCredentials.load_from_JSON(args.credpath)
except CredentialsFormatError:
sys.stdout.write('error')
return
except HandleSyntaxError:
sys.stdout.write('error')
return
# retrieve and set extra values
extra_config = {}
# create a handle to put. Concate the prefix with a new generated suffix
prefix = str(credentials.get_prefix())
uid = uuid.uuid1()
suffix = str(uid)
handle = prefix+"/"+suffix
try:
# setup connection to handle server
client = EUDATHandleClient.instantiate_with_credentials(
credentials,
**extra_config)
except HandleNotFoundException:
sys.stdout.write('error')
return
overwrite=False
result = create_execution(client, handle, args.location, overwrite, args.checksum, args.loc10320, args.extratype)
sys.stdout.write(result)
示例4: test_config_from_json
def test_config_from_json(self):
"""Test credentials instantiation from JSON file, with config."""
path_to_json_credentials = PATH_CRED+'/credentials_correct_withconfig_PUBLIC.json'
inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials)
jsonfilecontent = json.loads(open(path_to_json_credentials, 'r').read())
self.assertEqual(inst.get_config()['foo'], jsonfilecontent['foo'],
'Config not the same as in json file.')
self.assertEqual(inst.get_config()['bar'], jsonfilecontent['bar'],
'Config not the same as in json file.')
示例5: test_getters
def test_getters(self):
"""Test credentials instantiation from JSON file."""
path_to_json_credentials = PATH_CRED+'/credentials_correct_PUBLIC.json'
inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials)
jsonfilecontent = json.loads(open(path_to_json_credentials, 'r').read())
self.assertEqual(inst.get_username(), jsonfilecontent['username'],
'Username not the same as in json file.')
self.assertEqual(inst.get_password(), jsonfilecontent['password'],
'Password not the same as in json file.')
self.assertEqual(inst.get_server_URL(), jsonfilecontent['baseuri'],
'Server URL not the same as in json file.')
示例6: main
def main():
# parse command line options and arguments:
modes=['x','xmlfiles','j','jsonfiles','c','ckandatasets','p','pids','x-p', 'x-j', 'j-c','j-p']
p = options_parser(modes)
options,arguments = p.parse_args()
# check option 'mode' and generate process list:
(mode, pstat) = pstat_init(p,modes,options.mode,options.source,options.host)
# check for quiet mode
if (options.quiet):
qmsg='would be'
mainmode='check'
else:
qmsg='is'
mainmode='deletion'
if options.host :
print "\tCKAN HOST:\t%s" % (options.host)
if options.handle_check :
print "\tCREDENTIAL:\t%s" % (options.handle_check)
print '='*90
# make jobdir
now = time.strftime("%Y-%m-%d %H:%M:%S")
jid = os.getpid()
print "\tStart of processing:\t%s" % (now)
global logger
OUT = Output(pstat,now,jid,options)
##HEW-D logger = log.getLogger()
## logger
logger = OUT.setup_custom_logger('root',options.verbose)
# create credentials if required
if (options.handle_check):
try:
cred = PIDClientCredentials.load_from_JSON('credentials_11098')
except Exception, err:
logger.critical("[CRITICAL] %s Could not create credentials from credstore %s" % (err,options.handle_check))
p.print_help()
sys.exit(-1)
else:
logger.debug("Create EUDATHandleClient instance")
HandleClient = EUDATHandleClient.instantiate_with_credentials(cred,HTTPS_verify=True)
示例7: relation
def relation(args):
"""perform the relation action"""
try:
# load credentials
credentials = PIDClientCredentials.load_from_JSON(args.credpath)
except CredentialsFormatError:
sys.stdout.write('error')
return
except HandleSyntaxError:
sys.stdout.write('error')
return
# retrieve and set extra values
extra_config = {}
try:
# setup connection to handle server
client = EUDATHandleClient.instantiate_with_credentials(
credentials,
**extra_config)
except HandleNotFoundException:
sys.stdout.write('error')
return
result = 'None'
# add relation to 10320/LOC
try:
client.add_additional_URL(args.ppid, args.cpid)
except HandleAuthenticationError:
result = 'error'
except HandleNotFoundException:
result = 'False'
except HandleSyntaxError:
result = 'error'
sys.stdout.write(result)
示例8: bulk
def bulk(args):
"""perform the bulk actions"""
try:
# open input file
bulk_input_file = open(args.input, "r")
except:
sys.stdout.write('error opening: '+args.input)
return
try:
# open result file
bulk_result_file = open(args.result, "w")
except:
sys.stdout.write('error opening: '+args.result)
return
try:
# load credentials
credentials = PIDClientCredentials.load_from_JSON(args.credpath)
except CredentialsFormatError:
sys.stdout.write('error')
return
except HandleSyntaxError:
sys.stdout.write('error')
return
# retrieve and set extra values
extra_config = {}
try:
# setup connection to handle server
client = EUDATHandleClient.instantiate_with_credentials(
credentials,
**extra_config)
except HandleNotFoundException:
sys.stdout.write('error')
return
for line in bulk_input_file:
bulk_array = line.split()
if bulk_array[0] == 'SEARCH':
# search key value # search handle which matches criteria
search_key = bulk_array[1]
search_value = bulk_array[2]
result = search_execution(client, search_key, search_value)
bulk_result_file.write('search handle key: '+search_key+' value: '+search_value+' result: '+result+'\n')
if bulk_array[0] == 'READ':
# READ handle # read whole handle
# READ handle key # read key/value pair from handle
read_handle = bulk_array[1]
if len(bulk_array) >= 3:
read_key = bulk_array[2]
result = read_execution(client, read_handle, read_key)
bulk_result_file.write('read handle: '+read_handle+' key: '+read_key+' result: '+result+'\n')
else:
result = read_execution(client, read_handle)
bulk_result_file.write('read handle: '+read_handle+' result: '+result+'\n')
if bulk_array[0] == 'CREATE':
# CREATE prefix/uuid URL # create handle, use uuid for suffix
# CREATE prefix/suffix URL # create handle, use suffix for handle, no check before if handle exists
# CREATE prefix/uuid URL CHECKSUM # create handle, use uuid for suffix, add checksum
# CREATE prefix/uuid URL CHECKSUM 10320/LOC # create handle, use uuid for suffix, add checksum, add 10320/LOC
# CREATE prefix/uuid URL CHECKSUM 10320/LOC EXTRATYPE # create handle, use uuid for suffix, add checksum, add 10320/LOC, add extratypes
overwrite=False
checksum = None
loc10320 = None
extratype = None
# create a handle to put.
prefix = str(credentials.get_prefix())
create_prefix = bulk_array[1].split("/")[0]
create_suffix = bulk_array[1].split("/")[1]
if create_suffix == 'uuid':
uid = uuid.uuid1()
suffix = str(uid)
handle = prefix+"/"+suffix
else:
handle = prefix+"/"+create_suffix
overwrite=True
if len(bulk_array) == 3:
result = create_execution(client, handle, bulk_array[2], overwrite)
else:
if len(bulk_array) >= 4 and bulk_array[3].lower() != 'none':
checksum = bulk_array[3]
if len(bulk_array) >= 5 and bulk_array[4].lower() != 'none':
loc10320 = bulk_array[4]
if len(bulk_array) >= 6 and bulk_array[5].lower() != 'none':
extratype = bulk_array[5]
result = create_execution(client, handle, bulk_array[2], overwrite, checksum, loc10320, extratype)
bulk_result_file.write('create handle: '+bulk_array[1]+' result: '+result+'\n')
#.........这里部分代码省略.........
示例9: test_credentials_from_json_invalid_username
def test_credentials_from_json_invalid_username(self):
"""Exception occurs if user name in json file is not index:prefix/suffix."""
path_to_json_credentials = PATH_CRED+'/credentials_wrongusername_PUBLIC.json'
with self.assertRaises(HandleSyntaxError):
_inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials)
示例10: test_credentials_from_json_username_without_index
def test_credentials_from_json_username_without_index(self):
"""Exception occurs if user name in json file does not have an index."""
path_to_json_credentials = PATH_CRED+'/credentials_noindex_PUBLIC.json'
with self.assertRaises(HandleSyntaxError):
_inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials)
示例11: test_credentials_from_json
def test_credentials_from_json(self):
"""Test credentials instantiation from JSON file."""
path_to_json_credentials = PATH_CRED+'/credentials_correct_PUBLIC.json'
inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials)
self.assertIsInstance(inst, PIDClientCredentials)
示例12: test_credentials_from_json_empty_items
def test_credentials_from_json_empty_items(self):
"""Exception occurs if items are empty in json credentials file."""
path_to_json_credentials = PATH_CRED+'/credentials_usernameempty_PUBLIC.json'
with self.assertRaises(CredentialsFormatError):
_inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials)
示例13: print
dataset_dict["CHECKSUM"]=hashlib.md5(json.dumps(dataset_dict, encoding='latin1').strip()).hexdigest()
# Verbose information about the data
if args.verbose > 0 : print(' The dataset to upload:\n\t%s' % dataset_dict)
# Use the json module to dump the dictionary to a string for posting.
data_string = urllib.quote(json.dumps(dataset_dict))
# By default package_create function is used to create a new dataset.
request = urllib2.Request(
'http://'+args.ipadress+'/api/action/package_create')
# Create a handle client and check handle if required
handlestatus="unknown"
if (args.handle_check):
try:
cred = PIDClientCredentials.load_from_JSON(args.handle_check)
client = EUDATHandleClient.instantiate_with_credentials(cred)
except Exception as err:
print ("%s : Could not create credentials from credstore %s" % (err,args.handle_check))
sys.exit(-1)
else:
if args.verbose > 1 : print ("HandleClient created")
pidRecord=dict()
try:
pid = cred.get_prefix() + '/eudat-jmd_' + dataset_dict['name']
rec = client.retrieve_handle_record_json(pid)
except Exception as err :
print ("ERROR : %s in client.retrieve_handle_record_json()" % (err))
else:
if args.verbose > 0 : print(" Retrieved Handle %s with\n |%-12s\t|%-30s\t|%-30s|\n %s" % (pid,'Attribute','Value','Changed value',80*'-'))
示例14: test_credentials_from_json_broken_syntax
def test_credentials_from_json_broken_syntax(self):
""""""
path_to_json_credentials = PATH_CRED+'/credentials_brokensyntax_PUBLIC.json'
with self.assertRaises(CredentialsFormatError):
_inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials)
示例15: process
def process(options,pstat,OUT):
## process (options,pstat,OUT) - function
# Starts processing as specified in pstat['tbd'] and
# according the request list given bey the options
#
# Parameters:
# -----------
# 1. options (OptionsParser object)
# 2. pstat (process status dict)
#
# set list of request lsits for single or multi mode:
mode = None
procOptions=['community','source','verb','mdprefix','mdsubset','target_mdschema']
if(options.source):
mode = 'single'
mandParams=['community','verb','mdprefix'] # mandatory processing params
for param in mandParams :
if not getattr(options,param) :
logger.critical("Processing parameter %s is required in single mode" % param)
sys.exit(-1)
reqlist=[[
options.community,
options.source,
options.verb,
options.mdprefix,
options.mdsubset,
options.ckan_check,
options.handle_check,
options.target_mdschema
]]
elif(options.list):
mode = 'multi'
logger.debug(' |- Joblist: \t%s' % options.list)
reqlist=parse_list_file(options)
logger.debug(' |- Requestlist: \t%s' % reqlist)
## check job request (processing) options
logger.debug('|- Command line options')
for opt in procOptions :
if hasattr(options,opt) : logger.debug(' |- %s:\t%s' % (opt.upper(),getattr(options,opt)))
## GENERATION mode:
if (pstat['status']['g'] == 'tbd'):
logger.info('\n|- Generation started : %s' % time.strftime("%Y-%m-%d %H:%M:%S"))
GEN = Generator(OUT,pstat,options.outdir)
process_generate(GEN,reqlist)
## HARVESTING mode:
if (pstat['status']['h'] == 'tbd'):
logger.info('\n|- Harvesting started : %s' % time.strftime("%Y-%m-%d %H:%M:%S"))
HV = Harvester(OUT,pstat,options.outdir,options.fromdate)
process_harvest(HV,reqlist)
## MAPPINING - Mode:
if (pstat['status']['m'] == 'tbd'):
logger.info('\n|- Mapping started : %s' % time.strftime("%Y-%m-%d %H:%M:%S"))
MP = Mapper(OUT,options.outdir,options.fromdate)
process_map(MP,reqlist)
## VALIDATING - Mode:
if (pstat['status']['v'] == 'tbd'):
logger.info(' |- Validating started : %s' % time.strftime("%Y-%m-%d %H:%M:%S"))
VD = Validator(OUT,options.outdir,options.fromdate)
process_validate(VD,reqlist)
## CONVERTING - Mode:
if (pstat['status']['c'] == 'tbd'):
logger.info('\n|- Converting started : %s' % time.strftime("%Y-%m-%d %H:%M:%S"))
CV = Converter(OUT,options.outdir,options.fromdate)
process_convert(CV, reqlist)
## UPLOADING - Mode:
if (pstat['status']['u'] == 'tbd'):
logger.info('\n|- Uploading started : %s' % time.strftime("%Y-%m-%d %H:%M:%S"))
# create CKAN object
CKAN = CKAN_CLIENT(options.iphost,options.auth)
# create credentials and handle client if required
if (options.handle_check):
try:
cred = PIDClientCredentials.load_from_JSON('credentials_11098')
except Exception as err:
logger.critical("%s : Could not create credentials from credstore %s" % (err,options.handle_check))
##p.print_help()
sys.exit(-1)
else:
logger.debug("Create EUDATHandleClient instance")
HandleClient = EUDATHandleClient.instantiate_with_credentials(cred)
else:
cred=None
HandleClient=None
UP = Uploader(CKAN,options.ckan_check,HandleClient,cred,OUT,options.outdir,options.fromdate,options.iphost)
logger.info(' |- Host: \t%s' % CKAN.ip_host )
process_upload(UP, reqlist)
## DELETING - Mode:
if (pstat['status']['d'] == 'tbd'):
# start the process deleting:
#.........这里部分代码省略.........