def setUp(self): endpoint = os.environ.get('FLUIDDB_ENDPOINT', 'http://localhost:9000') username = os.environ.get('FLUIDDB_ADMIN_USERNAME', 'fluiddb') password = os.environ.get('FLUIDDB_ADMIN_PASSWORD', 'secret') self.fluiddb = Fluid(endpoint) self.fluiddb.login(username, password) self.fluiddb.bind()
def __init__(self): endpoint = os.environ['FLUIDDB_ENDPOINT'] username = os.environ['FLUIDDB_ADMIN_USERNAME'] password = os.environ['FLUIDDB_ADMIN_PASSWORD'] self.solrURL = os.environ['FLUIDDB_INDEXING_SERVER_URL'] self.fluiddb = Fluid(endpoint) self.fluiddb.login(username, password)
def generateData(username, password, endpoint): """Worker function creates random data. Requests to create namespaces, tags and values are continuously generated. This function never returns. @param username: The username to connect as. @param password: The password to use. @param endpoint: The Fluidinfo API endpoint to make requests against. """ fluidinfo = Fluid(endpoint) fluidinfo.login(username, password) fluidinfo.bind() while True: try: generateNamespaceData(username) except StandardError, e: logQueue.put(('ERROR %s' % str(e), ()))
from fom.session import Fluid from json import loads import os import sys if len(sys.argv) != 1: print >> sys.stderr, 'Usage: %s < manifest.json' % sys.argv[0] sys.exit(1) APP_ID = 'nknjamdijihneiclbpmcmfklakjkgdpf' codebase = ( 'https://fluiddb.fluidinfo.com/about/tabcast/fluidinfo.com/chrome.crx') version = loads(sys.stdin.read())['version'] fdb = Fluid('https://fluiddb.fluidinfo.com') password = os.environ['FLUIDDB_FLUIDINFO_DOT_COM_PASSWORD'] fdb.login('fluidinfo.com', password) about = 'tabcast' tag = 'fluidinfo.com/chrome-update.xml' data = '''<?xml version='1.0' encoding='UTF-8'?> <gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'> <app appid='%(id)s'> <updatecheck codebase='%(codebase)s' version='%(version)s' /> </app> </gupdate> ''' % { 'codebase': codebase, 'id': APP_ID,
def setUp(self): # sort out FluidDB fdb = Fluid('https://sandbox.fluidinfo.com') fdb.bind() fdb.login('test', 'test')
# optionally create a logger - you don't need to do this but it's good to be # able to see what's been going on since flimp logs pretty much everything # it's doing. logger = logging.getLogger("flimp") logger.setLevel(logging.DEBUG) logfile_handler = logging.FileHandler('flimp.log') logfile_handler.setLevel(logging.DEBUG) log_format = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - "\ "%(message)s") logfile_handler.setFormatter(log_format) logger.addHandler(logfile_handler) # Use fom to create a session with FluidDB - remember flimp uses fom for # connecting to FluidDB fdb = Fluid('https://sandbox.fluidinfo.com') # we'll use the sandbox fdb.login('test', 'test') # replace these with something that works fdb.bind() # Values to pass into the "process" function root_dir = 'test_dir' # the path to the directory you want to import root_path = 'test/foo' # the namespace in FluidDB that maps to root_dir name = 'dataset_name' # the name of the filesystem data to be imported desc = 'Plain English dataset description' # exactly what it says uuid = None # the uuid of the object to tag about = None # the about value of the object to tag preview = False # True will cause flimp to print out the preview # Make magic happen... obj = process(root_dir, root_path, name, desc, uuid, about, preview) # obj is a fom.mapping.Object instance representing the FluidDB object that
for sAbout, dictTags in dictObjects.items(): print "Commiting:", sAbout fdb.values.put(query='fluiddb/about = "' + sAbout + '"', values=dictTags) if __name__ == "__main__": ############################# # Bind to FluidInfo instance fileCredentials = open(os.path.expanduser('~/.fluidDBcredentials'), 'r') username = fileCredentials.readline().strip() password = fileCredentials.readline().strip() fileCredentials.close() # fdb = Fluid('https://sandbox.fluidinfo.com') # The sandbox instance fdb = Fluid() # The main instance fdb.login(username, password) fdb.bind() nsUser = Namespace(username) sUserNS = nsUser.path # Ugly use of a global, I know. :-) dictObjects = dict() fRequest = urllib2.urlopen(urlISOcodeListing) # Get enconding of raw listing. # This should usually be UTF-8, but it could change and cause a big headache! # sEncoding = fRequest.headers['content-type'].split('charset=')[-1] # ^^^^This is not working, since http://loc.org is not specifying the encoding. Dammit! # fRequest.headers['content-type'] = 'text/plain'
def execute(): """ Grab a bunch of args from the command line, verify and get the show on the road """ parser = OptionParser(version="%prog " + flimp.VERSION) parser.add_option('-f', '--file', dest='filename', help='The FILE to process (valid filetypes: %s)' % ', '.join(VALID_FILETYPES.keys()), metavar="FILE") parser.add_option('-d', '--dir', dest='directory', help="The root directory for a filesystem import into"\ " FluidDB") parser.add_option('-u', '--uuid', dest="uuid", default="", help="The uuid of the object to which the filesystem"\ " import is to attach its tags") parser.add_option('-a', '--about', dest="about", default="", help="The about value of the object to which the"\ " filesystem import is to attach its tags") parser.add_option('-p', '--preview', action="store_true", dest="preview", help="Show a preview of what will happen, don't import"\ " anything", default=False) parser.add_option('-i', '--instance', dest='instance', default="https://fluiddb.fluidinfo.com", help="The URI for the instance of FluidDB to use") parser.add_option('-l', '--log', dest='log', default="flimp.log", help="The log file to write to (defaults to flimp.log)") parser.add_option('-v', '--verbose', dest='verbose', default=False, action="store_true", help="Display status messages to"\ " console") parser.add_option('-c', '--check', dest='check', default=False, action="store_true", help="Validate the data file"\ " containing the data to import into FluidDB - don't"\ " import anything") options, args = parser.parse_args() # Some options validation if not (options.filename or options.directory): parser.error("You must supply either a source file or root directory"\ " to import.") if options.filename and options.directory: parser.error("You may only supply either a source file OR root"\ " directory to import (not both).") if options.uuid and options.about: parser.error("You may only supply either an object's uuid OR its"\ " about tag value (not both).") # Setup logging properly logger = logging.getLogger("flimp") logger.setLevel(logging.DEBUG) logfile_handler = logging.FileHandler(options.log) logfile_handler.setLevel(logging.DEBUG) log_format = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") logfile_handler.setFormatter(log_format) logger.addHandler(logfile_handler) # verbose..? if options.verbose: # console handler ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) ch.setFormatter(log_format) logger.addHandler(ch) if options.check: # No need to get information from the user if we're just validating # the file. A bit hacky! username = password = root_path = name = desc = about = "" else: # In the same way that sphinx interrogates the user using q&a we need to # assemble some more data that is probably not so easy to grab from the # arguments of the command username = get_argument('FluidDB username') password = get_argument('FluidDB password', password=True) root_path = get_argument('Absolute Namespace path (under which imported'\ ' namespaces and tags will be created)') if options.filename: name = get_argument( 'Name of dataset (defaults to filename)', os.path.basename(options.filename).split('.')[0]) about = get_argument('Key field for about tag value (if none given,'\ ' will use anonymous objects)', required=False) else: name = get_argument('Name of dataset') desc = get_argument('Description of the dataset') # Dump the recently collected information into the log file logger.info('FluidDB instance: %r' % options.instance) logger.info('Username: %r' % username) logger.info('Absolute Namespace path: %r' % root_path) logger.info('Dataset name: %r' % name) logger.info('Dataset description: %r' % desc) # Log into FluidDB fdb = Fluid(options.instance) fdb.bind() fdb.login(username, password) # Process the file or directory try: print "Working... (this might take some time, why not: tail -f the"\ " log?)" if options.filename: msg = process_file(options.filename, root_path, name, desc, about, options.preview, options.check) logger.info(msg) print msg else: obj = process_directory(options.directory, root_path, name, desc, options.uuid, options.about, options.preview) if obj: msg = 'Tags added to object with uuid: %s' % obj.uid logger.info(msg) print msg except Exception, e: # We want to catch all exceptions so we can log them nicely ex_type, ex_val, ex_trace = sys.exc_info() for msg in format_exception(ex_type, ex_val, ex_trace): logger.critical(msg) # this will be handled nicely by the try of last resort in the # flimp command line tool raise e
def run(self, host, username=None, password=None): if username is None: username = u'fluiddb' if password is None: password = u'secret' if host.find('://') == -1: host = 'http://' + host print 'Logging to', host fluiddb = Fluid(host) fluiddb.login(username, password) print 'Creating an object...', try: result = fluiddb.objects.post(u'test-object') objectID = result.value[u'id'] assert result.status == 201 except: print >> sys.stderr, 'FAILED' print_exc() else: print 'OK' tagname = 'test' + str(datetime.now().toordinal()) print 'Creating a tag...', try: result = fluiddb.tags[username].post(tagname, None, True) assert result.status == 201 except: print >> sys.stderr, 'FAILED' print_exc() else: print 'OK' print 'Creating a tag value...', try: path = '{0}/{1}'.format(username, tagname) result = fluiddb.about['test-object'][path].put(200) assert result.status == 204 except: print >> sys.stderr, 'FAILED' print_exc() else: print 'OK' print 'Giving time to the DIH (2 minutes)...' time.sleep(120) print 'Making a solr query...', try: path = '{0}/{1}'.format(username, tagname) result = fluiddb.objects.get('{0} = 200'.format(path)) print result.value[u'ids'] assert result.value[u'ids'] == [objectID] except: print >> sys.stderr, 'FAILED' print_exc() else: print 'OK' print 'Removing a tag value...', try: path = '{0}/{1}'.format(username, tagname) result = fluiddb.about['test-object'][path].delete() assert result.status == 204 except: print >> sys.stderr, 'FAILED' print_exc() else: print 'OK' print 'Removing a tag...', try: path = '{0}/{1}'.format(username, tagname) result = fluiddb.tags[path].delete() assert result.status == 204 except: print >> sys.stderr, 'FAILED' print_exc() else: print 'OK'