本文整理汇总了Python中eulfedora.server.Repository.ingest方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.ingest方法的具体用法?Python Repository.ingest怎么用?Python Repository.ingest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eulfedora.server.Repository
的用法示例。
在下文中一共展示了Repository.ingest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FedoraTestCase
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import ingest [as 别名]
class FedoraTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self, *args, **kwargs)
self.fedora_fixtures_ingested = []
self.pidspace = FEDORA_PIDSPACE
self.repo = Repository(FEDORA_ROOT, FEDORA_USER, FEDORA_PASSWORD)
# fixture cleanup happens in tearDown, which doesn't always run
# if a test fails - clean up stale test objects from a previous run here
stale_objects = list(self.repo.find_objects(pid__contains="%s:*" % self.pidspace))
if stale_objects:
print "Removing %d stale test object(s) in pidspace %s" % (len(stale_objects), self.pidspace)
for obj in stale_objects:
try:
self.repo.purge_object(obj.pid)
except RequestFailed as rf:
logger.warn("Error purging stale test object %s (TestCase init): %s" % (obj.pid, rf))
def setUp(self):
# NOTE: queries require RI flush=True or test objects will not show up in RI
self.repo.risearch.RISEARCH_FLUSH_ON_QUERY = True
self.opener = self.repo.opener
self.api = ApiFacade(self.opener)
fixtures = getattr(self, "fixtures", [])
for fixture in fixtures:
self.ingestFixture(fixture)
def tearDown(self):
for pid in self.fedora_fixtures_ingested:
try:
self.repo.purge_object(pid)
except RequestFailed as rf:
logger.warn("Error purging test object %s in tear down: %s" % (pid, rf))
def getNextPid(self):
pidspace = getattr(self, "pidspace", None)
return self.repo.get_next_pid(namespace=pidspace)
def loadFixtureData(self, fname):
data = load_fixture_data(fname)
# if pidspace is specified, get a new pid from fedora and set it as the pid in the xml
if hasattr(self, "pidspace"):
xml = xmlmap.load_xmlobject_from_string(data, _MinimalFoxml)
xml.pid = self.getNextPid()
return xml.serialize()
else:
return data
def ingestFixture(self, fname):
object = self.loadFixtureData(fname)
pid = self.repo.ingest(object)
if pid:
# we'd like this always to be true. if ingest fails we should
# throw an exception. that probably hasn't been thoroughly
# tested yet, though, so we'll check it until it has been.
self.append_test_pid(pid)
def append_test_pid(self, pid):
self.fedora_fixtures_ingested.append(pid)
示例2: Command
# 需要导入模块: from eulfedora.server import Repository [as 别名]
# 或者: from eulfedora.server.Repository import ingest [as 别名]
class Command(BaseCommand):
def get_password_option(option, opt, value, parser):
setattr(parser.values, option.dest, getpass())
help = """Generate missing Fedora content model objects and load initial objects."""
# NOTE: will need to be converted to add_argument / argparse
# format for django 11 (optparse will be removed)
option_list = BaseCommand.option_list + (
make_option('--username', '-u',
dest='username',
action='store',
help='''Username to connect to fedora'''),
make_option('--password',
dest='password',
action='callback', callback=get_password_option,
help='''Prompt for password required when username used'''
))
def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs)
def handle(self, *args, **options):
repo_args = {}
if options.get('username') is not None:
repo_args['username'] = options.get('username')
if options.get('password') is not None:
repo_args['password'] = options.get('password')
self.repo = Repository(**repo_args)
self.verbosity = int(options.get('verbosity', 1))
# FIXME/TODO: add count/summary info for content models objects created ?
if self.verbosity > 1:
sys.stdout.write("Generating content models for %d classes"
% len(DigitalObject.defined_types))
for cls in DigitalObject.defined_types.itervalues():
self.process_class(cls)
self.load_initial_objects()
def process_class(self, cls):
try:
ContentModel.for_class(cls, self.repo)
except ValueError as v:
# for_class raises a ValueError when a class has >1
# CONTENT_MODELS.
if self.verbosity > 1:
sys.stderr.write(v)
except RequestFailed as rf:
if hasattr(rf, 'detail'):
if 'ObjectExistsException' in rf.detail:
# This shouldn't happen, since ContentModel.for_class
# shouldn't attempt to ingest unless the object doesn't exist.
# In some cases, Fedora seems to report that an object doesn't exist,
# then complain on attempted ingest.
full_name = '%s.%s' % (cls.__module__, cls.__name__)
logger.warn('Fedora error (ObjectExistsException) on Content Model ingest for %s' % \
full_name)
else:
# if there is a detail message, display that
sys.stderr.write("Error ingesting ContentModel for %s: %s"
% (cls, rf.detail))
def load_initial_objects(self):
# look for any .xml files in apps under fixtures/initial_objects
# and attempt to load them as Fedora objects
# NOTE! any fixtures should have pids specified, or new versions of the
# fixture will be created every time syncrepo runs
app_module_paths = []
if hasattr(django_apps, 'get_app_configs'):
apps = django_apps.get_app_configs()
else:
apps = get_apps()
# monkey see django code, monkey do
for app in apps:
# newer django AppConfig
if hasattr(app, 'path'):
app_module_paths.append(app.path)
elif hasattr(app, '__path__'):
# It's a 'models/' subpackage
for path in app.__path__:
app_module_paths.append(path)
else:
# It's a models.py module
app_module_paths.append(app.__file__)
app_fixture_paths = [os.path.join(os.path.dirname(path),
'fixtures', 'initial_objects', '*.xml')
for path in app_module_paths]
fixture_count = 0
load_count = 0
#.........这里部分代码省略.........