本文整理汇总了Python中eulfedora.server.Repository.get_object方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.get_object方法的具体用法?Python Repository.get_object怎么用?Python Repository.get_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eulfedora.server.Repository
的用法示例。
在下文中一共展示了Repository.get_object方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PdfToTextTest
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
class PdfToTextTest(unittest.TestCase):
fixture_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures')
pdf_filepath = os.path.join(fixture_dir, 'test.pdf')
pdf_text = 'This is a short PDF document to use for testing.'
def setUp(self):
self.repo = Repository(settings.FEDORA_ROOT, settings.FEDORA_USER,
settings.FEDORA_PASSWORD)
with open(self.pdf_filepath) as pdf:
self.pdfobj = self.repo.get_object(type=TestPdfObject)
self.pdfobj.label = 'eulindexer test pdf object'
self.pdfobj.pdf.content = pdf
self.pdfobj.save()
def tearDown(self):
self.repo.purge_object(self.pdfobj.pid)
def test_file(self):
# extract text from a pdf from a file on the local filesystem
text = pdf_to_text(open(self.pdf_filepath, 'rb'))
self.assertEqual(self.pdf_text, text)
def test_object_datastream(self):
# extract text from a pdf datastream in fedora
pdfobj = self.repo.get_object(self.pdfobj.pid, type=TestPdfObject)
text = pdf_to_text(pdfobj.pdf.content)
self.assertEqual(self.pdf_text, text)
示例2: volume_modified
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def volume_modified(request, pid):
'last modification time for a single volume'
solr = solr_interface()
results = solr.query(content_model=VolumeV1_0.VOLUME_CONTENT_MODEL,
pid=pid) \
.sort_by('-timestamp').field_limit('timestamp')
# NOTE: using solr indexing timestamp instead of object last modified, since
# if an object's index has changed it may have been modified,
# and index timestamp for a volume will be updated when pages are added
# if a user is logged in, page should show as modified
# when annotation count changes
latest_note = None
if request.user.is_authenticated():
# NOTE: shouldn't be very expensive to init volume here; not actually
# making any api calls, just using volume to get volume
# uri and associated annotations
repo = Repository()
vol = repo.get_object(pid, type=Volume)
# newest annotation creation for pages in this volume
latest_note = vol.annotations().visible_to(request.user) \
.last_created_time()
solrtime = results[0]['timestamp'] if results.count() else None
return solrtimestamp_or_datetime(solrtime, latest_note)
示例3: process
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def process(self, input):
"""
Write the input to the given path.
"""
if input is None:
return
#if not os.environ.get("NODETREE_WRITE_FILEOUT"):
# return input
repo = Repository(self._params.get("url"), self._params.get("username"),
self._params.get("password"))
try:
buf = StringIO()
Image.fromarray(input).save(buf, self._params.get("format").upper())
except IOError:
raise exceptions.NodeError(
"Error obtaining image buffer in format: %s" %
self._params.get("format").upper(), self)
pclass = get_fedora_proxy_class(self._params.get("dsid"))
obj = repo.get_object(self._params.get("pid"), type=pclass)
obj.DATASTREAM.content = buf
obj.DATASTREAM.label = "Test Ingest Datastream 1"
obj.DATASTREAM.mimetype = "image/%s" % self._params.get("format")
obj.save()
return input
示例4: main
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def main(argv):
repo = Repository(root='%s/fedora/' % HOST, username='%s' % fedoraUser, password='%s' % fedoraPass)
risearch = repo.risearch
query = 'select ?pid where {?pid <fedora-view:disseminates> ?ds . ?pid <fedora-model:hasModel> <info:fedora/islandora:pageCModel> . ?ds <fedora-view:disseminationType> <info:fedora/*/PDF>}'
pids = risearch.find_statements(query, language='sparql', type='tuples', flush=None)
#total = 0
for dictionary in pids:
for key in dictionary:
p = dictionary[key]
pid = p.replace('info:fedora/', '')
obj = repo.get_object(pid)
pdf = obj.getDatastreamObject("PDF")
#size = pdf.size
#total += size
obj.api.purgeDatastream(pid, "PDF")
obj.save()
print "Purged PDF for %s" % pid
示例5: _load_postcard
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def _load_postcard(self, label, description, subjects, filename):
'''Create a postcard object and load to fedora.
:param label: object label and dc:title
:param description: object dc:description
:param subjects: list of subjects to be set in dc:subject
:param filename: filename for image content, assumed relative to current directory
'''
# NOTE: image object init here somewhat redundant with current postcard ingest logic
repo = Repository()
obj = repo.get_object(type=ImageObject)
obj.label = label
obj.owner = settings.FEDORA_OBJECT_OWNERID
obj.dc.content.title = obj.label
obj.dc.content.description_list.extend(description)
obj.dc.content.subject_list.extend(subjects)
# common DC for all postcards
obj.dc.content.type = 'image'
# FIXME: configure this somewhere?
obj.dc.content.relation_list.extend([settings.RELATION,
'http://beck.library.emory.edu/greatwar/'])
# set file as content of image datastream
obj.image.content = open(path.join(fixture_path, filename))
# add relation to postcard collection
obj.rels_ext.content.add((
URIRef(obj.uri),
URIRef(MEMBER_OF_COLLECTION),
URIRef(PostcardCollection.get().uri)
))
obj.save()
self.postcards.append(obj)
示例6: Command
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
class Command(BaseCommand):
''' This command run through all the articles and makes sure that journal titles and publishers match against Sherpa Romeo
'''
args = "[netid netid ...]"
help = __doc__
option_list = BaseCommand.option_list + (
make_option('--noact', '-n',
action='store_true',
default=False,
help='Fixed all caps title in articles'),
)
def handle(self, *args, **options):
self.verbosity = int(options['verbosity']) # 1 = normal, 0 = minimal, 2 = all
self.v_normal = 1
#connection to repository
self.repo = Repository(settings.FEDORA_ROOT, username=settings.FEDORA_MANAGEMENT_USER, password=settings.FEDORA_PASSWORD)
pid_set = self.repo.get_objects_with_cmodel(Publication.ARTICLE_CONTENT_MODEL, type=Publication)
coll = self.repo.get_object(pid=settings.PID_ALIASES['oe-collection'])
try:
articles = Paginator(pid_set, 100)
except Exception as e:
self.output(0, "Error paginating items: : %s " % (e.message))
#process all Articles
for p in articles.page_range:
try:
objs = articles.page(p).object_list
except Exception as e:
#print error and go to next iteration of loop
self.output(0,"Error getting page: %s : %s " % (p, e.message))
continue
for article in objs:
try:
if not article.exists:
self.output(0, "Skipping %s because pid does not exist" % article.pid)
continue
else:
print coll
print article.pid
article.collection = coll
ark_uri = '%sark:/25593/%s' % (settings.PIDMAN_HOST, article.pid.split(':')[1])
article.dc.content.identifier_list.extend([ark_uri])
article.save()
except Exception as e:
self.output(0, "Error processing pid: %s : %s " % (article.pid, e.message))
# self.counts['errors'] +=1
def output(self, v, msg):
'''simple function to handle logging output based on verbosity'''
if self.verbosity >= v:
self.stdout.write("%s\n" % msg)
示例7: get
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def get(self, request):
context = {}
item_id = request.GET.get('id', None)
fmt = request.GET.get('format', None)
if item_id is not None:
context['id'] = item_id
repo = Repository(request=self.request)
# generalized class-based view would need probably a get-item method
# for repo objects, could use type-inferring repo variant
obj = repo.get_object(item_id, type=Volume)
formats = obj.unapi_formats
if fmt is None:
# display formats for this item
context['formats'] = formats
else:
current_format = formats[fmt]
# return requested format for this item
meth = getattr(obj, current_format['method'])
return HttpResponse(meth(), content_type=current_format['type'])
else:
# display formats for all items
# NOTE: if multiple classes, should be able to combine the formats
context['formats'] = Volume.unapi_formats
# NOTE: doesn't really even need to be a template, could be generated
# with eulxml just as easily if that simplifies reuse
return render(request, 'books/unapi_format.xml', context,
content_type='application/xml')
示例8: download_file
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def download_file(pid, dsid):
repo = Repository(testsettings.FEDORA_ROOT_NONSSL, testsettings.FEDORA_USER,
testsettings.FEDORA_PASSWORD)
obj = repo.get_object(pid)
ds = obj.getDatastreamObject(dsid)
widgets = ['Download: ', progressbar.widgets.Percentage(), ' ',
progressbar.widgets.Bar(), ' ', progressbar.widgets.ETA(),
' ', progressbar.widgets.FileTransferSpeed()]
# set initial progressbar size based on file; will be slightly larger because
# of multipart boundary content
pbar = progressbar.ProgressBar(widgets=widgets, max_value=ds.size).start()
# download content to a tempfile
tmpfile = tempfile.NamedTemporaryFile(
prefix='%s-%s_' % (pid, dsid), delete=False)
print('writing to ', tmpfile.name)
size_read = 0
try:
for chunk in ds.get_chunked_content():
size_read += len(chunk)
pbar.update(size_read)
tmpfile.write(chunk)
except Exception:
raise
示例9: main
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def main(argv):
pids = []
s = solr.SolrConnection('%s/solr' % HOST)
repo = Repository(root='%s/fedora/' % HOST, username='%s' % fedoraUser, password='%s' % fedoraPass)
results = repo.risearch.sparql_query('PREFIX dime: <http://dimenovels.org/ontology#> select ?pid where {?pid <fedora-rels-ext:isMemberOfCollection> <info:fedora/dimenovels:fame> . OPTIONAL { ?pid dime:IsCopyOf ?copy } FILTER (! BOUND(?copy)) }')
for row in results:
for k, v in row.items():
pids.append(v.replace('info:fedora/', ''))
with open('C:/Users/a1691506/Desktop/ffw_editions.csv', mode='r') as infile:
reader = csv.reader(infile)
editionDict = {rows[0]:rows[1] for rows in reader}
for p in pids:
print "Processing %s" % p
try:
response = s.query('PID:"%s"' % p)
for hit in response.results:
number = hit['mods_series_number_ms'][0].split(' ')[1]
editionUri = editionDict[number]
obj = repo.get_object(p)
obj.add_relationship('http://dimenovels.org/ontology#IsCopyOf', editionUri)
obj.save()
except:
print "%s failed. Check it!" % p
continue
示例10: main
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def main(argv):
csvfile = open ("C:/Users/a1691506/Desktop/repo_size.csv", 'wb')
csvwriter = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
repo = Repository(root='%s/fedora/' % HOST, username='%s' % fedoraUser, password='%s' % fedoraPass)
risearch = repo.risearch
query = 'select ?pid ?date where {?pid <fedora-model:hasModel> <info:fedora/fedora-system:FedoraObject-3.0> ; <fedora-model:createdDate> ?date . } ORDER BY ASC(?date)'
pids = risearch.find_statements(query, language='sparql', type='tuples', flush=None)
repo_size = 0
for dictionary in pids:
p = dictionary['pid']
pid = p.replace('info:fedora/', '')
dateCreated = dictionary['date']
total_size = 0
obj = repo.get_object(pid)
datastreams = obj.ds_list
for datastream in datastreams:
ds = obj.getDatastreamObject(datastream)
size = ds.size
total_size += size
repo_size += total_size
print "Total size for %s: %s" % (pid, total_size)
csvwriter.writerow([pid, dateCreated, total_size, repo_size])
示例11: datastream_etag
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def datastream_etag(request, pid, dsid, type=None, repo=None, accept_range_request=False, **kwargs):
"""Method suitable for use as an etag function with
:class:`django.views.decorators.http.condition`. Takes the same
arguments as :meth:`~eulfedora.views.raw_datastream`.
"""
# if a range is requested and it is not for the entire file,
# do *NOT* return an etag
if accept_range_request and request.META.get("HTTP_RANGE", None) and request.META["HTTP_RANGE"] != "bytes=1-":
return None
try:
if repo is None:
repo = Repository()
get_obj_opts = {}
if type is not None:
get_obj_opts["type"] = type
obj = repo.get_object(pid, **get_obj_opts)
ds = obj.getDatastreamObject(dsid)
if ds and ds.exists and ds.checksum_type != "DISABLED":
return ds.checksum
except RequestFailed:
pass
return None
示例12: postcard_image
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def postcard_image(request, pid, size):
'''Lin to postcard image in requested size.
:param pid: postcard object pid
:param size: size to return, one of thumbnail, medium, or large
'''
# NOTE: formerly this served out actual image content, via
# fedora dissemination & djatoka
# Images now use an IIIF image server; adding redirects here
# for the benefit of search engines or indexes referencing
# the old urls
try:
repo = Repository()
obj = repo.get_object(pid, type=ImageObject)
if not obj.exists:
raise Http404
if size == 'thumbnail':
url = obj.thumbnail_url
elif size == 'medium':
url = obj.medium_img_url
elif size == 'large':
url = obj.large_img_url
return HttpResponsePermanentRedirect(url)
except RequestFailed:
raise Http404
示例13: handle
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def handle(self, *pids, **options):
# bind a handler for interrupt signal
signal.signal(signal.SIGINT, self.interrupt_handler)
verbosity = int(options.get('verbosity', self.v_normal))
repo = Repository()
try:
pidman = DjangoPidmanRestClient()
except Exception as err:
# error if pid manager config options not in localsettings
raise CommandError(err)
old_page_target = '%s/books/pages/' % Site.objects.get_current().domain
search_args = {'type':'ark', 'target': old_page_target, 'count': 10}
# get a small result set to retrieve the total
results = pidman.search_pids(**search_args)
total = results['results_count']
# then set a larger page size for actual processing
search_args['count'] = 100
if verbosity >= self.v_normal:
print 'Found %d total page ARKs with targets to be updated' % total
pbar = ProgressBar(widgets=[Percentage(),
' (', Counter(), ')',
Bar(),
ETA()],
maxval=total).start()
self.stats = defaultdict(int)
self.processed = set()
for ark in self.get_search_results(pidman, search_args):
self.processed.add(ark['pid'])
# get fedora pid from target uri
target_uri = ark['targets'][0]['target_uri']
baseurl, pid = target_uri.rstrip('/').rsplit('/', 1)
try:
page = repo.get_object(pid, type=Page)
# this should probably only happen in dev/qa
if not page.exists:
if verbosity > self.v_normal:
self.stderr.write('Page %s does not exist' % pid)
self.stats['notfound'] += 1
else:
# check if volume exists?
pidman.update_ark_target(ark['pid'], target_uri=page.absolute_url)
self.stats['updated'] += 1
except RequestFailed as rf:
print 'Error accessing %s: %s' % (pid, rf)
self.stats['error'] += 1
pbar.update(len(self.processed))
if self.interrupted:
break
if not self.interrupted:
pbar.finish()
# summarize
self.stderr.write('Updated %(updated)d, %(error)d error(s), %(notfound)d not found' \
% self.stats)
示例14: VolumePageList
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
class VolumePageList(ListView, VaryOnCookieMixin):
'''Display a paginated list of :class:`~readux.books.models.Page`
objects associated with a single :class:`~readux.books.models.Volume`.
Pages are displayed by thumbnail; thumbnails include an annotation count
indicator for logged in users with annotations.
'''
template_name = 'books/volume_pages_list.html'
paginate_by = 30
context_object_name = 'pages'
@method_decorator(last_modified(view_helpers.volume_pages_modified))
def dispatch(self, *args, **kwargs):
return super(VolumePageList, self).dispatch(*args, **kwargs)
def get_queryset(self):
self.repo = Repository(request=self.request)
# store the volume for use in get_context_data
self.vol = self.repo.get_object(self.kwargs['pid'], type=Volume)
if not self.vol.exists or not self.vol.is_a_volume:
raise Http404
return self.vol.find_solr_pages()
def get_context_data(self, **kwargs):
context_data = super(VolumePageList, self).get_context_data()
context_data.update({
'vol': self.vol,
'form': BookSearch(), # form for searching in this book
})
# if user is authenticated, check for annotations on this volume
if self.request.user.is_authenticated():
notes = self.vol.page_annotation_count(self.request.user)
# method returns a dict for easy lookup;
# strip out base site url for easy lookup in the template
# (need leading / left to match item urls)
domain = get_current_site(self.request).domain.rstrip('/')
if not domain.startswith('https'):
domain = 'https://' + domain
annotated_pages = dict([(k.replace(domain, ''), v)
for k, v in notes.iteritems()])
else:
annotated_pages = {}
context_data.update({
'annotated_pages': annotated_pages,
'annotation_search_enabled': bool(annotated_pages)
})
# Check if the first page of the volume is wider than it is tall
# to set the layout of the pages
first_page = self.vol.pages[0]
if first_page.width > first_page.height:
layout = 'landscape'
else:
layout = 'default'
context_data['layout'] = layout
return context_data
示例15: get_object
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import get_object [as 别名]
def get_object(self, queryset=None):
# kwargs are set based on configured url pattern
pid = self.kwargs['pid']
repo = Repository(request=self.request)
vol = repo.get_object(pid, type=Volume)
if not vol.exists or not vol.is_a_volume:
raise Http404
return vol