Ejemplo n.º 1
0
def get_client():
    """Returns an instance of fcrepo..client.FedoraClient with the connection 
    settings specified in settings.py"""
    
    connection = Connection(FEDORA_INSTANCE, 
            username=RTV_FEDORA_USER, 
            password=RTV_FEDORA_PASSWORD)
    return FedoraClient(connection)
Ejemplo n.º 2
0
    def __init__(self,
                 content_models,
                 host='localhost',
                 port=61613,
                 user='',
                 passcode='',
                 fedora_url=''):
        '''
        Constructor
        '''
        self.conn = Connection([(host, port)], user, passcode)
        self.conn.set_listener('', self)
        self.conn.start()
        logging.info('Connecting to STOMP server %(host)s on port %(port)s.' %
                     {
                         'host': host,
                         'port': port
                     })
        self.transaction_id = None
        logging.info("Connecting to Fedora server at %(url)s" %
                     {'url': fedora_url})
        self.fc = fcrepo.connection.Connection(fedora_url,
                                               username=user,
                                               password=passcode)
        self.client = FedoraClient(self.fc)
        self.fedora_url = fedora_url
        self.username = user
        self.password = passcode

        # Create plugin manager
        self.manager = PluginManager(
            categories_filter={"FedoraMicroService": FedoraMicroService})
        plugin_path = os.path.dirname(__file__)
        self.manager.setPluginPlaces([plugin_path + "/plugins"])

        # Load plugins.
        self.manager.locatePlugins()
        self.manager.loadPlugins()
        self.contentModels = {}

        for plugin in self.manager.getPluginsOfCategory("FedoraMicroService"):
            # plugin.plugin_object is an instance of the plubin
            logging.info(
                "Loading plugin: %(name)s for content model %(cmodel)s." % {
                    'name': plugin.plugin_object.name,
                    'cmodel': plugin.plugin_object.content_model
                })
            plugin.plugin_object.config = config
            if type(plugin.plugin_object.content_model) == types.StringType:
                content_models = [plugin.plugin_object.content_model]
            else:
                content_models = plugin.plugin_object.content_model
            for content_model in content_models:
                if content_model in self.contentModels:
                    self.contentModels[content_model].append(
                        plugin.plugin_object)
                else:
                    self.contentModels[content_model] = [plugin.plugin_object]
Ejemplo n.º 3
0
def startFcrepo():
    '''
helper function that starts up the fedora connection
'''
    connection = Connection(fedoraUrl,
                            username=fedoraUserName,
                            password=fedoraPassword)

    global fedora
    try:
        fedora = FedoraClient(connection)
    except FedoraConnectionException:
        logging.error('Error connecting to fedora, exiting' + '\n')
        sys.exit()
    return True
Ejemplo n.º 4
0
    def __init__(self,
                 host='localhost',
                 port=61613,
                 user='',
                 passcode='',
                 fedora_url=''):
        self.conn = Connection([(host, port)], user, passcode)
        self.conn.set_listener('', self)
        self.conn.start()
        self.transaction_id = None
        self.fc = fcrepo.connection.Connection(fedora_url,
                                               username=user,
                                               password=passcode)
        self.client = FedoraClient(self.fc)

        self.fedora_url = fedora_url
        self.user = user
        self.password = passcode
    #get config
    config = ConfigParser.ConfigParser()
    config.read(os.path.join(source_directory, 'HAMILTON.cfg'))
    #config.read(os.path.join(source_directory,'TEST.cfg'))
    solrUrl = config.get('Solr', 'url')
    fedoraUrl = config.get('Fedora', 'url')
    fedoraUserName = config.get('Fedora', 'username')
    fedoraPassword = config.get('Fedora', 'password')

    #get fedora connection
    connection = Connection(fedoraUrl,
                            username=fedoraUserName,
                            password=fedoraPassword)
    try:
        fedora = FedoraClient(connection)
    except FedoraConnectionException:
        logging.error('Error connecting to fedora, exiting' + '\n')
        sys.exit()

    #setup the directories
    mods_directory = os.path.join(source_directory, 'mods-xml')
    if not os.path.isdir(mods_directory):
        logging.error('MODS directory invalid \n')
        sys.exit()

    tei_directory = os.path.join(source_directory, 'tei-xml')
    if not os.path.isdir(tei_directory):
        logging.error('TEI directory invalid \n')
        sys.exit()
Ejemplo n.º 6
0
fedora_url = 'http://localhost:8080/fedora'
username = '******'
password = '******'
log_filename = 'script.log'

body = ''
pids = [
    #pids to work on here
]

levels = {
    'DEBUG': logging.DEBUG,
    'INFO': logging.INFO,
    'WARNING': logging.WARNING,
    'ERROR': logging.ERROR,
    'CRITICAL': logging.CRITICAL,
    'FATAL': logging.FATAL
}

logging.basicConfig(filename=log_filename, level=levels['INFO'])
fc = fcrepo.connection.Connection(fedora_url,
                                  username=username,
                                  password=password)
client = FedoraClient(fc)

for pid in pids:
    obj = client.getObject(pid)
    logging.info("Processing Pid: %s" % (obj.pid))
    for dsid in obj:
        co.runRules(obj, dsid, body)
Ejemplo n.º 7
0

def connectToFedora(url, user, pw):
    """
    Attempt to create a connection to fedora using the supplied username and password.  If the
    connection succeeds, return the connected fedora client, otherwise return None.  The calling
    function should terminate if None is received.
    """
    try:
        connection = Connection(url, username=user, password=pw)
    except Exception, ex:
        print("Error while connecting to fedoraUrl: %s", ex.message)
        return None

    try:
        return FedoraClient(connection)
    except Exception, ex:
        print("Exception while opening fedora client")
        print(
            "Check if fedora is running and your login information is correct")
    return None


""" ====== MANAGING FEDORA OBJECTS ====== """


def createRelsExt(childObject,
                  parentPid,
                  contentModel,
                  extraNamespaces={},
                  extraRelationships={}):
Ejemplo n.º 8
0
 def connect(self):
     self.conn.start()
     self.fc = fcrepo.connection.Connection(self.fedora_url,
                                            username=self.username,
                                            password=self.password)
     self.client = FedoraClient(self.fc)