本文整理汇总了Python中tardis.tardis_portal.models.Experiment.get_or_create_directory方法的典型用法代码示例。如果您正苦于以下问题:Python Experiment.get_or_create_directory方法的具体用法?Python Experiment.get_or_create_directory怎么用?Python Experiment.get_or_create_directory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tardis.tardis_portal.models.Experiment
的用法示例。
在下文中一共展示了Experiment.get_or_create_directory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transfer_experiment
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import get_or_create_directory [as 别名]
#.........这里部分代码省略.........
exps = Experiment.objects.all()
got_lock = True
if not acquire_lock():
logger.warning("another worker has access to consume experiment")
return
duplicate_exp = 0
for exp in exps:
#logger.warn("exp = %s" % exp.id)
params = ExperimentParameter.objects.filter(name=key_name,
parameterset__schema=key_schema,
parameterset__experiment=exp)
#logger.warn("params.count() = %s" % params.count())
if params.count() >= 1:
key = params[0].string_value
if key == key_value:
duplicate_exp = exp.id
#logger.warn("found duplicate for %s" % duplicate_exp)
break
if duplicate_exp:
logger.warn("Found duplicate experiment form %s exp %s to exp %s"
% (source, exp_id, duplicate_exp))
if got_lock:
release_lock()
return
# TODO: Need someway of updating and existing experiment. Problem is
# that copy will have different id from original, so need unique identifier
# to allow matching
# We have not pulled everything we need from producer and are ready to create
# experiment.
# Make placeholder experiment and ready metadata
e = Experiment(
title='Placeholder Title',
approved=True,
created_by=found_user,
public_access=exp_state,
locked=False # so experiment can then be altered.
)
e.save()
# store the key
#eps, was_created = ExperimentParameterSet.objects.\
# get_or_create(experiment=e, schema=key_schema)
#if was_created:
# logger.warn("was created")
#ep, was_created = ExperimentParameter.objects.get_or_create(parameterset=eps,
# name=key_name,
# string_value=key_value)
#if was_created:
# logger.warn("was created again")
#ep.save()
if got_lock:
release_lock()
local_id = e.id
filename = path.join(e.get_or_create_directory(),
'mets_upload.xml')
f = open(filename, 'wb+')
f.write(metsxml)
f.close()
# Ingest this experiment META data and isOwner ACLS
eid = None
try:
eid, sync_path = _registerExperimentDocument(filename=filename,
created_by=found_user,
expid=local_id,
owners=owners)
logger.info('=== processing experiment %s: DONE' % local_id)
except:
# FIXME: what errors can mets return?
msg = '=== processing experiment %s: FAILED!' \
% local_id
logger.error(msg)
raise MetsParseError(msg)
# FIXME: if METS parse fails then we should go back and delete the placeholder experiment
exp = Experiment.objects.get(id=eid)
# so that tardis does not copy the data
for datafile in exp.get_datafiles():
datafile.stay_remote = True
datafile.save()
#import nose.tools
#nose.tools.set_trace()
# FIXME: reverse lookup of URLs seem quite slow.
# TODO: put this information into specific metadata schema attached to experiment
exp.description += get_audit_message(source, exp_id)
exp.save()
local_ids.append(local_id)
return local_ids
示例2: register_experiment_ws_xmldata
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import get_or_create_directory [as 别名]
def register_experiment_ws_xmldata(request):
''' Web-service mechanism for registering an experiment, and triggering a corresponding file transfer.
Although intended to be called as a web service, it actually works fine as a normal form, at
/experiment/register '''
# --- start function body ---
global experiment, idless_statuses, current_action, debug_POST
experiment=None
idless_statuses=[]
logger.debug("Starting ingest process")
# Check that we have received a form, abort otherwise
try:
if request.method != 'POST':
# Happens when just viewing the form
form = RegisterExperimentForm() # An unbound form
return send_retry_response(request, form, '')
logger.info("Starting experiment ingest processing")
from datetime import datetime
temp_title = "Ingest Received: " + \
datetime.now().strftime("%A, %d. %B %Y %I:%M%p")
# A form bound to the POST data
form = RegisterExperimentForm(request.POST, request.FILES)
# Check that the form is filled out, abort otherwise.
if not form.is_valid():
fail_message = "Form validation failure: <br/>" \
"Form Errors: " + str(form.errors) + "<br/>" \
try:
add_status(RegistrationStatus.ERROR, fail_message)
return send_retry_response(request, form, '')
except Exception as ex:
logger.error("Really an exception %s" % ex)
logger.debug("Form validation: ok")
xmldata = request.FILES['xmldata']
xmldata_meta = xmldata.name
username = form.cleaned_data['username']
originid = form.cleaned_data['originid']
from_url = form.cleaned_data['from_url']
owners = request.POST.getlist('experiment_owner')
debug_POST = "username: " + username + "<br/>" \
"xmldata: " + xmldata_meta + "<br/>" \
"originid: " + originid + "<br/>" \
"from_url: " + from_url + "<br/>" \
user = auth_service.authenticate(request=request,
authMethod=localdb_auth_key)
# Check user is authenticated, and user information is present, abort otherwise
if not authentication_ok(user):
return return_response_error(request)
logger.debug("User authentication: ok")
# Basic checks have passed, so create the experiment.
global experiment
experiment = Experiment(title=temp_title, approved=True, created_by=user,)
experiment.save()
# Now update old registration statuses with the new experiment number.
for oldstatus in idless_statuses:
rs = RegistrationStatus.objects.get(pk=oldstatus)
rs.experiment=experiment
rs.save()
# If no owner provided, record a warning.
check_owner(owners)
# Write the submitted XML file to disk
filename = path.join(experiment.get_or_create_directory(),
'mets_upload.xml')
f = open(filename, 'wb+')
for chunk in xmldata.chunks():
f.write(chunk)
f.close()
add_status(status=RegistrationStatus.PASS,
message="Ingest Successfully Received")
# Now process METS/XML file
current_action = "Ingest Processing"
try:
_registerExperimentDocument(filename=filename,
created_by=user,
expid=experiment.id,
owners=owners,
username=username)
except:
add_status(status=RegistrationStatus.ERROR,
message="METS metadata ingest failed",
exception=True)
return return_response_error(request)
#.........这里部分代码省略.........
示例3: register_experiment_ws_xmldata
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import get_or_create_directory [as 别名]
def register_experiment_ws_xmldata(request):
status = ''
if request.method == 'POST': # If the form has been submitted...
# A form bound to the POST data
form = RegisterExperimentForm(request.POST, request.FILES)
if form.is_valid(): # All validation rules pass
xmldata = request.FILES['xmldata']
username = form.cleaned_data['username']
origin_id = form.cleaned_data['originid']
from_url = form.cleaned_data['from_url']
user = auth_service.authenticate(request=request,
authMethod=localdb_auth_key)
if user:
if not user.is_active:
return return_response_error(request)
else:
return return_response_error(request)
e = Experiment(
title='Placeholder Title',
approved=True,
created_by=user,
)
e.save()
eid = e.id
filename = path.join(e.get_or_create_directory(),
'mets_upload.xml')
f = open(filename, 'wb+')
for chunk in xmldata.chunks():
f.write(chunk)
f.close()
logger.info('=== processing experiment: START')
owners = request.POST.getlist('experiment_owner')
try:
_registerExperimentDocument(filename=filename,
created_by=user,
expid=eid,
owners=owners,
username=username)
logger.info('=== processing experiment %s: DONE' % eid)
except:
logger.exception('=== processing experiment %s: FAILED!' % eid)
return return_response_error(request)
if from_url:
logger.debug('=== sending file request')
logger.info('Sending received_remote signal')
from tardis.tardis_portal.signals import received_remote
received_remote.send(sender=Experiment,
instance=e,
uid=origin_id,
from_url=from_url)
response = HttpResponse(str(eid), status=200)
response['Location'] = request.build_absolute_uri(
'/experiment/view/' + str(eid))
return response
else:
form = RegisterExperimentForm() # An unbound form
c = Context({
'form': form,
'status': status,
'subtitle': 'Register Experiment',
'searchDatafileSelectionForm': getNewSearchDatafileSelectionForm()})
return HttpResponse(render_response_index(request,
'tardis_portal/register_experiment.html', c))