Esempio n. 1
0
    def run(self, comment_url, database_uri=None):
        """Delete a comment, given its loveme.do URL.

        @param comment_url: A loveme.do comment URL, in the form
            http://loveme.do/comment/fluidinfo.com/terrycojones/
            2012-08-03T22:04:13.698896
        """
        database_uri = database_uri or 'postgres:///fluidinfo'
        setConfig(setupConfig(None))
        setupLogging(self.outf)
        setupStore(database_uri, 'main')

        try:
            importer, username, timestamp = parseCommentURL(comment_url)
        except ValueError as error:
            self._error(str(error))

        # Delete the comment & report status.
        count = CommentAPI(None).delete(importer, username, timestamp)

        if count == 0:
            self._error('Comment not found.')
        elif count == 1:
            transaction.commit()
            print >> self.outf, 'Comment deleted.'
            sys.exit(0)
        else:
            self._error('Unexpected return result (%r) trying to delete '
                        'comment.' % count)
Esempio n. 2
0
    def run(self,
            database_uri,
            username,
            email=None,
            fullname=None,
            password=None,
            role=None):

        if not any([email, fullname, password, role]):
            print(
                'You must provide an email, name, password, or role '
                'to update.')
            return

        if role is not None:
            try:
                role = Role.fromName(role)
            except LookupError:
                print 'Invalid role'
                return

        config = setupConfig(None)
        config.set('store', 'main-uri', database_uri)
        setConfig(config)
        setupLogging(self.outf)
        setupStore(database_uri, 'main')
        updateUser(username, password, fullname, email, role)
Esempio n. 3
0
    def run(self,
            database_uri,
            username,
            password,
            fullname,
            email,
            role=None):
        username = username.decode('utf-8')
        password = password.decode('utf-8')
        fullname = '' if fullname is None else fullname.decode('utf-8')
        email = '' if email is None else email.decode('utf-8')
        roles = {
            'anonymous': Role.ANONYMOUS,
            'superuser': Role.SUPERUSER,
            'user': Role.USER,
            'usermanager': Role.USER_MANAGER
        }
        role = roles.get(role.lower() if role else 'user')

        config = setupConfig(None)
        config.set('store', 'main-uri', database_uri)
        config.set('index', 'url', '')
        setConfig(config)
        setupLogging(self.outf)
        setupStore(database_uri, 'main')
        createUser(username, password, fullname, email, role)
Esempio n. 4
0
    def run(self, comment_url, database_uri=None):
        """Delete a comment, given its loveme.do URL.

        @param comment_url: A loveme.do comment URL, in the form
            http://loveme.do/comment/fluidinfo.com/terrycojones/
            2012-08-03T22:04:13.698896
        """
        database_uri = database_uri or 'postgres:///fluidinfo'
        setConfig(setupConfig(None))
        setupLogging(self.outf)
        setupStore(database_uri, 'main')

        try:
            importer, username, timestamp = parseCommentURL(comment_url)
        except ValueError as error:
            self._error(str(error))

        # Delete the comment & report status.
        count = CommentAPI(None).delete(importer, username, timestamp)

        if count == 0:
            self._error('Comment not found.')
        elif count == 1:
            transaction.commit()
            print >> self.outf, 'Comment deleted.'
            sys.exit(0)
        else:
            self._error('Unexpected return result (%r) trying to delete '
                        'comment.' % count)
Esempio n. 5
0
 def testSetupLoggingWithStream(self):
     """
     L{setupLogging} can configure logging to write messages to a stream.
     """
     stream = StringIO()
     setupLogging(stream=stream)
     logging.info('Test log message.')
     self.assertIn('Test log message.', stream.getvalue())
Esempio n. 6
0
 def make(self, dependency_resources):
     """Setup logging and return the log stream."""
     stream = StringIO()
     log = logging.getLogger()
     while log.handlers:
         log.removeHandler(log.handlers.pop())
     setupLogging(stream=stream, format=self._format)
     return stream
Esempio n. 7
0
 def run(self, database_uri):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     rows = reportErrorSummary(store)
     print_columns(self.outf, rows, shrink_index=2)
     print >> self.outf
     print '%s occurrences of %s errors' % (
         sum(int(item[0]) for item in rows), len(rows))
Esempio n. 8
0
 def run(self, database_uri, version):
     version = version.decode('utf-8')
     config = setupConfig(None)
     config.set('store', 'main-uri', database_uri)
     setConfig(config)
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     setVersionTag(version)
Esempio n. 9
0
 def run(self, database_uri, version):
     version = version.decode('utf-8')
     config = setupConfig(None)
     config.set('store', 'main-uri', database_uri)
     setConfig(config)
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     setVersionTag(version)
Esempio n. 10
0
 def run(self, database_uri):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     rows = reportErrorSummary(store)
     print_columns(self.outf, rows, shrink_index=2)
     print >> self.outf
     print '%s occurrences of %s errors' % (sum(
         int(item[0]) for item in rows), len(rows))
Esempio n. 11
0
 def testSetupLoggingWithStream(self):
     """
     L{setupLogging} can configure logging to write messages to a stream.
     """
     stream = StringIO()
     setupLogging(stream=stream)
     logging.info('Test log message.')
     self.assertIn('Test log message.', stream.getvalue())
Esempio n. 12
0
 def run(self, database_uri, max_rows_per_query=None):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     logging.info('Checking database:')
     if max_rows_per_query:
         checkIntegrity(max_rows_per_query)
     else:
         checkIntegrity()
Esempio n. 13
0
 def run(self, database_uri, limit=None):
     if limit is None:
         limit = 15
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     rows = list(reportTraceLogSummary(store, limit))
     print_columns(self.outf, rows)
     print >> self.outf
     print 'Top %s slowest requests' % limit
Esempio n. 14
0
 def run(self, database_uri, index_url, username):
     username = username.decode('utf-8')
     config = setupConfig(None)
     config.set('store', 'main-uri', database_uri)
     config.set('index', 'url', str(index_url))
     setConfig(config)
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     deleteUser(username)
Esempio n. 15
0
 def run(self, path, database_uri):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     schema = logs.createSchema()
     logging.info('Creating schema')
     patchDatabase(store, schema)
     logging.info('Loading log file %s', path)
     loadLogs(path, store)
     logging.info('Finished loading log file %s', path)
Esempio n. 16
0
 def run(self, path, database_uri, old_format=None):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     schema = logs.createSchema()
     logging.info('Creating schema')
     patchDatabase(store, schema)
     logging.info('Loading trace logs from %s', path)
     loadTraceLogs(path, store, old_format)
     logging.info('Finished loading trace logs from %s', path)
Esempio n. 17
0
 def run(self, database_uri, index_url, username):
     username = username.decode('utf-8')
     config = setupConfig(None)
     config.set('store', 'main-uri', database_uri)
     config.set('index', 'url', str(index_url))
     setConfig(config)
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     deleteUser(username)
Esempio n. 18
0
 def run(self, path, database_uri, old_format=None):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     schema = logs.createSchema()
     logging.info('Creating schema')
     patchDatabase(store, schema)
     logging.info('Loading trace logs from %s', path)
     loadTraceLogs(path, store, old_format)
     logging.info('Finished loading trace logs from %s', path)
Esempio n. 19
0
 def run(self, path, database_uri):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     schema = logs.createSchema()
     logging.info('Creating schema')
     patchDatabase(store, schema)
     logging.info('Loading log file %s', path)
     loadLogs(path, store)
     logging.info('Finished loading log file %s', path)
Esempio n. 20
0
 def run(self, database_uri, max_rows_per_query=None):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     logging.info('Checking database:')
     if max_rows_per_query:
         checkIntegrity(max_rows_per_query)
     else:
         checkIntegrity()
Esempio n. 21
0
 def run(self, database_uri, limit=None):
     if limit is None:
         limit = 15
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     rows = list(reportTraceLogSummary(store, limit))
     print_columns(self.outf, rows)
     print >> self.outf
     print 'Top %s slowest requests' % limit
Esempio n. 22
0
 def testSetupLoggingWithFile(self):
     """
     L{setupLogging} can configure logging to write messages to a file.
     """
     path = self.fs.makePath()
     setupLogging(path=path)
     logging.info('Log message.')
     logging.getLogger().handlers[0].flush()
     with open(path, 'r') as log:
         self.assertIn('Log message.', log.read())
Esempio n. 23
0
 def testSetupLoggingWithFile(self):
     """
     L{setupLogging} can configure logging to write messages to a file.
     """
     path = self.fs.makePath()
     setupLogging(path=path)
     logging.info('Log message.')
     logging.getLogger().handlers[0].flush()
     with open(path, 'r') as log:
         self.assertIn('Log message.', log.read())
Esempio n. 24
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     logging.info('Creating schema.')
     patchDatabase(store, schema)
     logging.info('Creating system data.')
     bootstrapSystemData(store)
     logging.info('Creating web admin data.')
     bootstrapWebAdminData()
Esempio n. 25
0
 def testSetupLoggingWithStreamSupportsUnicode(self):
     """
     The log configured by L{setupLogging} handles C{unicode} messages
     properly.
     """
     stream = StringIO()
     setupLogging(stream=stream)
     logging.info(u'\N{HIRAGANA LETTER A}')
     logging.getLogger().handlers[0].flush()
     self.assertIn(u'\N{HIRAGANA LETTER A}'.encode('utf-8'),
                   stream.getvalue())
Esempio n. 26
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     logging.info('Creating schema.')
     patchDatabase(store, schema)
     logging.info('Creating system data.')
     bootstrapSystemData(store)
     logging.info('Creating web admin data.')
     bootstrapWebAdminData()
Esempio n. 27
0
 def testSetupLoggingWithFileSupportsUnicode(self):
     """
     The log configured by L{setupLogging} handles C{unicode} messages
     properly.
     """
     path = self.fs.makePath()
     setupLogging(path=path)
     logging.info(u'\N{HIRAGANA LETTER A}')
     logging.getLogger().handlers[0].flush()
     with open(path, 'r') as log:
         self.assertIn(u'\N{HIRAGANA LETTER A}'.encode('utf-8'), log.read())
Esempio n. 28
0
 def testSetupLoggingWithFileSupportsUnicode(self):
     """
     The log configured by L{setupLogging} handles C{unicode} messages
     properly.
     """
     path = self.fs.makePath()
     setupLogging(path=path)
     logging.info(u'\N{HIRAGANA LETTER A}')
     logging.getLogger().handlers[0].flush()
     with open(path, 'r') as log:
         self.assertIn(u'\N{HIRAGANA LETTER A}'.encode('utf-8'), log.read())
Esempio n. 29
0
 def testSetupLoggingWithStreamSupportsUnicode(self):
     """
     The log configured by L{setupLogging} handles C{unicode} messages
     properly.
     """
     stream = StringIO()
     setupLogging(stream=stream)
     logging.info(u'\N{HIRAGANA LETTER A}')
     logging.getLogger().handlers[0].flush()
     self.assertIn(u'\N{HIRAGANA LETTER A}'.encode('utf-8'),
                   stream.getvalue())
Esempio n. 30
0
 def testSetupLoggingWithFileSupportsLogRotation(self):
     """
     L{setupLogging} uses a C{WatchedFileHandler} when a path is used.  The
     handler automatically reopens the log file if it gets moved, by
     logrotate for example.
     """
     path = self.fs.makePath()
     setupLogging(path=path)
     logging.info('Log message 1.')
     os.rename(path, '%s.1' % path)
     logging.info('Log message 2.')
     logging.getLogger().handlers[0].flush()
     with open(path, 'r') as log:
         self.assertIn('Log message 2.', log.read())
     with open('%s.1' % path, 'r') as log:
         self.assertIn('Log message 1.', log.read())
Esempio n. 31
0
 def testSetupLoggingWithFileSupportsLogRotation(self):
     """
     L{setupLogging} uses a C{WatchedFileHandler} when a path is used.  The
     handler automatically reopens the log file if it gets moved, by
     logrotate for example.
     """
     path = self.fs.makePath()
     setupLogging(path=path)
     logging.info('Log message 1.')
     os.rename(path, '%s.1' % path)
     logging.info('Log message 2.')
     logging.getLogger().handlers[0].flush()
     with open(path, 'r') as log:
         self.assertIn('Log message 2.', log.read())
     with open('%s.1' % path, 'r') as log:
         self.assertIn('Log message 1.', log.read())
Esempio n. 32
0
 def run(self, database_uri):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     rows = list(reportErrorTracebacks(store))
     for count, exceptionClass, message, traceback in rows:
         if count > 1:
             print >> self.outf, '%s occurrences of %s: %s' % (
                 count, exceptionClass, message)
         else:
             print >> self.outf, '%s occurrence of %s: %s' % (
                 count, exceptionClass, message)
         print >> self.outf
         for line in traceback.splitlines():
             print >> self.outf, '   ', line
         print >> self.outf
         print >> self.outf
     print >> self.outf, '%s occurrences of %s errors' % (sum(
         item[0] for item in rows), len(rows))
Esempio n. 33
0
 def run(self, database_uri):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     rows = list(reportErrorTracebacks(store))
     for count, exceptionClass, message, traceback in rows:
         if count > 1:
             print >> self.outf, '%s occurrences of %s: %s' % (
                 count, exceptionClass, message)
         else:
             print >> self.outf, '%s occurrence of %s: %s' % (
                 count, exceptionClass, message)
         print >> self.outf
         for line in traceback.splitlines():
             print >> self.outf, '   ', line
         print >> self.outf
         print >> self.outf
     print >> self.outf, '%s occurrences of %s errors' % (
         sum(item[0] for item in rows), len(rows))
Esempio n. 34
0
    def run(self, database_uri, username, password, fullname,
            email, role=None):
        username = username.decode('utf-8')
        password = password.decode('utf-8')
        fullname = '' if fullname is None else fullname.decode('utf-8')
        email = '' if email is None else email.decode('utf-8')
        roles = {'anonymous': Role.ANONYMOUS,
                 'superuser': Role.SUPERUSER,
                 'user': Role.USER,
                 'usermanager': Role.USER_MANAGER}
        role = roles.get(role.lower() if role else 'user')

        config = setupConfig(None)
        config.set('store', 'main-uri', database_uri)
        config.set('index', 'url', '')
        setConfig(config)
        setupLogging(self.outf)
        setupStore(database_uri, 'main')
        createUser(username, password, fullname, email, role)
Esempio n. 35
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     status = getPatchStatus(store, schema)
     if status.unknownPatches:
         unknownPatches = ', '.join('patch_%d' % version
                                    for version in status.unknownPatches)
         logging.critical('Database has unknown patches: %s',
                          unknownPatches)
         return 1
     if status.unappliedPatches:
         unappliedPatches = ', '.join(
             'patch_%d' % version for version in status.unappliedPatches)
         logging.info('Applying patches: %s', unappliedPatches)
         patchDatabase(store, schema)
     else:
         logging.info('Database is up-to-date.')
Esempio n. 36
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     status = getPatchStatus(store, schema)
     if status.unappliedPatches:
         patches = ', '.join('patch_%d' % version
                             for version in status.unappliedPatches)
         logging.info('Unapplied patches: %s' % patches)
         sys.exit(1)
     if status.unknownPatches:
         patches = ', '.join('patch_%d' % version
                             for version in status.unknownPatches)
         logging.info('Unknown patches: %s' % patches)
         sys.exit(2)
     if not status.unappliedPatches and not status.unknownPatches:
         logging.info('Database is up-to-date.')
         sys.exit(0)
Esempio n. 37
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     status = getPatchStatus(store, schema)
     if status.unknownPatches:
         unknownPatches = ', '.join(
             'patch_%d' % version for version in status.unknownPatches)
         logging.critical('Database has unknown patches: %s',
                          unknownPatches)
         return 1
     if status.unappliedPatches:
         unappliedPatches = ', '.join(
             'patch_%d' % version for version in status.unappliedPatches)
         logging.info('Applying patches: %s', unappliedPatches)
         patchDatabase(store, schema)
     else:
         logging.info('Database is up-to-date.')
Esempio n. 38
0
    def run(self, path_list, username=None, database_uri=None,
            batch_size=None):
        if database_uri is None:
            database_uri = 'postgres:///fluidinfo'
        if batch_size is None:
            batch_size = 100
        if username is None:
            print >> self.outf, 'You must provide a username.'
            sys.exit(1)

        setConfig(setupConfig(None))
        setupLogging(self.outf)
        setupStore(database_uri, 'main')

        client = DatasetImporter(batch_size)
        for filename in path_list:
            with open(filename, 'r') as file:
                data = load(file)
                client.upload(username, data['objects'])
Esempio n. 39
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     status = getPatchStatus(store, schema)
     if status.unappliedPatches:
         patches = ', '.join('patch_%d' % version
                             for version in status.unappliedPatches)
         logging.info('Unapplied patches: %s' % patches)
         sys.exit(1)
     if status.unknownPatches:
         patches = ', '.join('patch_%d' % version
                             for version in status.unknownPatches)
         logging.info('Unknown patches: %s' % patches)
         sys.exit(2)
     if not status.unappliedPatches and not status.unknownPatches:
         logging.info('Database is up-to-date.')
         sys.exit(0)
Esempio n. 40
0
    def run(self, database_uri, username, email=None, fullname=None,
            password=None, role=None):

        if not any([email, fullname, password, role]):
            print ('You must provide an email, name, password, or role '
                   'to update.')
            return

        if role is not None:
            try:
                role = Role.fromName(role)
            except LookupError:
                print 'Invalid role'
                return

        config = setupConfig(None)
        config.set('store', 'main-uri', database_uri)
        setConfig(config)
        setupLogging(self.outf)
        setupStore(database_uri, 'main')
        updateUser(username, password, fullname, email, role)
Esempio n. 41
0
    def run(self,
            path_list,
            username=None,
            database_uri=None,
            batch_size=None):
        if database_uri is None:
            database_uri = 'postgres:///fluidinfo'
        if batch_size is None:
            batch_size = 100
        if username is None:
            print >> self.outf, 'You must provide a username.'
            sys.exit(1)

        setConfig(setupConfig(None))
        setupLogging(self.outf)
        setupStore(database_uri, 'main')

        client = DatasetImporter(batch_size)
        for filename in path_list:
            with open(filename, 'r') as file:
                data = load(file)
                client.upload(username, data['objects'])
Esempio n. 42
0
 def run(self, database_uri, index_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     return buildIndex(str(index_uri))
Esempio n. 43
0
 def testSetupLoggingUsesRootLogger(self):
     """L{setupLogging} configures the C{logging} module's root logger."""
     stream = StringIO()
     log = setupLogging(stream=stream)
     self.assertIdentical(log, logging.getLogger())
Esempio n. 44
0
 def testSetupLoggingUsesDebugLevel(self):
     """L{setupLogging} uses the C{logging.INFO} log level, by default."""
     stream = StringIO()
     setupLogging(stream=stream)
     self.assertEqual(logging.INFO, logging.getLogger().level)
Esempio n. 45
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     removeTestingData()
Esempio n. 46
0
 def run(self, database_uri, filename, interval, max_objects):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     return batchIndex(filename, int(interval), int(max_objects))
Esempio n. 47
0
 def run(self, database_uri, index_uri, modified_since):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     modified_since = datetime.strptime(modified_since, '%Y-%m-%d')
     return updateIndex(str(index_uri), modified_since)
Esempio n. 48
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     prepareForTesting()
Esempio n. 49
0
 def run(self, index_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     return deleteIndex(str(index_uri))
Esempio n. 50
0
 def run(self, database_uri, index_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     return buildIndex(str(index_uri))
Esempio n. 51
0
 def run(self, database_uri, filename, interval, max_objects):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     return batchIndex(filename, int(interval), int(max_objects))
Esempio n. 52
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     prepareForTesting()
Esempio n. 53
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     removeTestingData()
Esempio n. 54
0
 def testSetupLoggingUsesDebugLevel(self):
     """L{setupLogging} uses the C{logging.INFO} log level, by default."""
     stream = StringIO()
     setupLogging(stream=stream)
     self.assertEqual(logging.INFO, logging.getLogger().level)
Esempio n. 55
0
 def testSetupLoggingWithCustomLevel(self):
     """L{setupLogging} sets the log level passed by the caller."""
     stream = StringIO()
     log = setupLogging(stream=stream, level=logging.CRITICAL)
     self.assertEqual(logging.CRITICAL, log.level)
Esempio n. 56
0
 def run(self, database_uri, index_uri, modified_since):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     setupStore(database_uri, 'main')
     modified_since = datetime.strptime(modified_since, '%Y-%m-%d')
     return updateIndex(str(index_uri), modified_since)
Esempio n. 57
0
 def run(self, index_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     return deleteIndex(str(index_uri))
Esempio n. 58
0
 def run(self, username, password, host, max_connections=None):
     setupLogging(self.outf)
     if max_connections is None:
         max_connections = 16
     endpoint = 'http://%s' % host
     generateLoad(username, password, endpoint, max_connections)
Esempio n. 59
0
 def testSetupLoggingWithCustomLevel(self):
     """L{setupLogging} sets the log level passed by the caller."""
     stream = StringIO()
     log = setupLogging(stream=stream, level=logging.CRITICAL)
     self.assertEqual(logging.CRITICAL, log.level)