Esempio n. 1
0
class Upload(object):
    def __init__(self, baseUrl, log, userAgent="Meresco-Fetch Harvester"):
        if not baseUrl:
            self._sruUpdateClient = _Ignore()
        else:
            _, netloc, path, _, _ = urlsplit(baseUrl)
            host, port = netloc.split(':', 1) if ':' in netloc else (netloc, 80)
            self._sruUpdateClient = SruUpdateClient(
                host=host,
                port=int(port),
                path=path,
                userAgent=userAgent,
                synchronous=True)
        self._log = log
        self._log.write("Uploading to: %s\n" % repr(baseUrl))

    def uploadRecord(self, identifier, data):
        self._upload(identifier, data)
        self._log.write("Uploaded: %s\n" % identifier)

    def deleteRecord(self, identifier):
        self._delete(identifier)
        self._log.write("Deleted: %s\n" % identifier)

    def _upload(self, identifier, data):
        consume(self._sruUpdateClient.add(identifier=identifier, data=data))

    def _delete(self, identifier):
        consume(self._sruUpdateClient.delete(identifier=identifier))
Esempio n. 2
0
 def __init__(self, baseUrl, log, userAgent="Meresco-Fetch Harvester"):
     if not baseUrl:
         self._sruUpdateClient = _Ignore()
     else:
         _, netloc, path, _, _ = urlsplit(baseUrl)
         host, port = netloc.split(':', 1) if ':' in netloc else (netloc, 80)
         self._sruUpdateClient = SruUpdateClient(
             host=host,
             port=int(port),
             path=path,
             userAgent=userAgent,
             synchronous=True)
     self._log = log
     self._log.write("Uploading to: %s\n" % repr(baseUrl))