API¶
Repository¶
-
class
ogre.repository.
Item
(id, directory)¶ An item in a repository.
An
Item
provides access to the underlying metadata files for an item in aRepository
. Different files are accessed as properties that return a path to the file:from ogre.repository import Item item = Item('id_1', 'path/to/repo') item.id # 'id_1' item.fgdc # 'path/to/repo/id_1/fgdc.xml'
Usually, items are obtained by iterating over a
Repository
object.Parameters: - id – item id
- directory – directory of repository
-
class
ogre.repository.
Repository
(path, remote, catalog_file='layers.json')¶ An object representing an OpenGeoMetadata repository.
A
Repository
creates a local clone of a repo. If the local repo already exists, it will attempt to do agit pull
. It can be iterated over to produceItem
s:from ogre.repository import Repository for item in Repository('path/to/local', 'path/to/remote'): print item.id
Parameters: - path – path to local repo
- remote – path to remote repo to clone
- catalog_file – name of catalog file in repo
-
catalog
= None¶ Repository catalog in dictionary format
-
commit
(message)¶ Perform
git commit
of repository.Parameters: message – commit message
-
update
()¶ Perform
git pull
of repository.
-
ogre.repository.
load_catalog
(path)¶ Load the JSON catalog file.
Parameters: path – path to JSON catalog file
Record¶
-
class
ogre.record.
Record
(**kwargs)¶ Defines a GeoBlacklight record.
A record’s fields (see https://github.com/geoblacklight/geoblacklight-schema) can be initialized through keyword arguments or set later:
from ogre.record import Record record = Record(dc_title_s=u'Cambridge Libraries') record.dct_provenance_s = u'MIT'
This class can be easily subclassed to create a specific kind of record:
from ogre.record import Record from ogre.fields import String, Enum class MitRecord(Record): dct_provenance_s = String(default=u'MIT') dc_rights_s = Enum(enums=[u'Public', u'Restricted'], default=u'Restricted')
Parameters: kwargs – initial field values -
as_dict
()¶ Return record as a dictionary.
This dictionary will contain only fields present in the current version of the GeoBlacklight schema.
The
dct_references_s
field, if notNone
, will be represented as a valid JSON string.Return type: dictionary
-
Fields¶
The Ogre Toolkit provides a declarative API for defining a
Record
. Use the fields documented here to
create new kinds of records.
-
class
ogre.fields.
Default
(default=None)¶ A field type mixin that supports default values.
Fields using this can define a default value:
from ogre.record import Record from ogre.fields import Default class MyField(Default): pass class MyRecord(Record): default_field = MyField(default='Is this dress blue and black?') record = MyRecord() record.default_field # 'Is this dress blue and black?'
-
class
ogre.fields.
String
(strip_ws=True)¶ Bases:
ogre.fields.Descriptor
,ogre.fields.Default
A string field type.
By default, white space will be removed from the beginning and end of the string. Set
strip_ws
toFalse
to disable this behavior.Parameters: strip_ws – remove white space from string, default is True
-
class
ogre.fields.
Decimal
¶ Bases:
ogre.fields.Descriptor
,ogre.fields.Default
A decimal field type.
Calls
decimal.Decimal()
on any value being set.
-
class
ogre.fields.
Integer
¶ Bases:
ogre.fields.Descriptor
,ogre.fields.Default
An integer field type.
Calls
int()
on any value being set.
-
class
ogre.fields.
DateTime
¶ Bases:
ogre.fields.Descriptor
,ogre.fields.Default
An arrow datetime field.
-
class
ogre.fields.
Set
¶ Bases:
ogre.fields.Descriptor
A
set
field type.Example usage:
from ogre.record import Record record = Record() record.dct_spatial_sm.add("Boston") record.dct_spatial_sm.update(["Cambridge", "Boston"]) record.dct_spatial_sm # set(["Boston", "Cambridge"])
-
class
ogre.fields.
Enum
(enums, mapper=lambda x: x)¶ Bases:
ogre.fields.Descriptor
,ogre.fields.Default
Enumerable field type.
This defines a field that accepts values from a predetermined list. A mapper function can be passed that is called on the value being set right before it is set. For example:
from ogre.record import Record from ogre.fields import Enum class MyRecord(Record): places = Enum(enums=['MFA', 'MOBA'], mapper=lambda x: x.upper()) record = MyRecord(places='moba') record.places # MOBA
Parameters: - enums – list of valid values
- mapper – mapper function
-
class
ogre.fields.
Dictionary
¶ Bases:
ogre.fields.Descriptor
A
dict
field type.
XML Parsers¶
-
class
ogre.xml.
FGDCParser
¶ An FGDC XML parser.
-
end_handler
(elem)¶ End handler called when encountering the end of an element.
-
record
= None¶ Parsed GeoBlacklight record
-
start_handler
(elem)¶ Start handler called when encountering a new element.
No-op.
-
-
ogre.xml.
parse
(fp, parser)¶ Parse XML data using the specified parser.
A parser class must implement at least two methods,
start_handler
andend_handler
, which accept anElement
. These methods must populate an instance propertyrecord
which is returned when parsing is complete.Parameters: - source – file name or file pointer containing XML data
- parser – parser class to use for parsing