Example #1
0
    def execute(self, query, modify=False):
        try:
            cursor = orm2.datasource.datasource_base.execute(
                self, query, modify)

        except psycopg.ProgrammingError as err:
            # In any case rollback the current transaction.
            # For one thing to get rid of that stupid "current transaction is
            # aborted, commands ignored until end of transaction block"
            self.rollback()
            
            error_message = str(err)
            if "duplicate key" in error_message:
                raise DuplicateKey(error_message, err)
            else:
                raise BackendError(error_message, err)
            
        except psycopg.Error as err:
            self._dbfailures += 1
            if self._dbfailures < self._ERRORS_BEFORE_RECONNECT:
                try:
                    if hasattr(self, "_update_cursor"):
                        del self._update_cursor
                    if hasattr(self, "db"):
                        del self._conn.db
                except:
                    raise sys.exc_type(sys.exc_value).with_traceback(sys.exc_traceback)

                self.execute(query, modify)
            else:
                raise sys.exc_type(sys.exc_value).with_traceback(sys.exc_traceback)
            
        return cursor 
Example #2
0
    def execute(self, query, modify=False):
        try:
            cursor = orm2.datasource.datasource_base.execute(
                self, query, modify)

        except psycopg.ProgrammingError as err:
            # In any case rollback the current transaction.
            # For one thing to get rid of that stupid "current transaction is
            # aborted, commands ignored until end of transaction block"
            self.rollback()

            error_message = str(err)
            if "duplicate key" in error_message:
                raise DuplicateKey(error_message, err)
            else:
                raise BackendError(error_message, err)

        except psycopg.Error as err:
            self._dbfailures += 1
            if self._dbfailures < self._ERRORS_BEFORE_RECONNECT:
                try:
                    if hasattr(self, "_update_cursor"):
                        del self._update_cursor
                    if hasattr(self, "db"):
                        del self._conn.db
                except:
                    raise sys.exc_type(sys.exc_value).with_traceback(
                        sys.exc_traceback)

                self.execute(query, modify)
            else:
                raise sys.exc_type(sys.exc_value).with_traceback(
                    sys.exc_traceback)

        return cursor
Example #3
0
    def run(self):
        try:
            while not self.quitting:
                queueObj = self.ssh_connect_queue.get()
                if queueObj == "quit":
                    self.quit()

                #                success, command_output = attemptConnection(host, username, password, timeout, commands)
                attemptConnection(queueObj)

                # hmm, this is weird...
                if queueObj.connection_result:
                    queueObj.connection_result = "SUCCESS"
                else:
                    queueObj.connection_result = "FAILED"

                self.output_queue.put(queueObj)
                self.ssh_connect_queue.task_done()
                # just for progress, etc...
                if queueObj.output_callback:
                    queueObj.output_callback()
        except Exception, detail:
            print _("Exception: %s") % detail
            print sys.exc_type()
            print traceback.print_tb(sys.exc_info()[2])
            #            self.output_queue.task_done()
            #            self.ssh_connect_queue.task_done()
            self.quit()
Example #4
0
    def execute(self, query, modify=False):
        """
        Run a query on the database connection.

        This function also performs failure accounting and will
        re-connect to the database if a certain threshold has passed.
        """
        if type(query) == UnicodeType:
            query = query.encode(self.backend_encoding())
        try:
            cursor = orm2.datasource.datasource_base.execute(
                self, query, modify)
        except psycopg.ProgrammingError as err:
            # In any case rollback the current transaction.
            # For one thing to get rid of that stupid "current transaction is
            # aborted, commands ignored until end of transaction block"
            self.rollback()

            error_message = str(err)
            if "duplicate key" in error_message:
                raise DuplicateKey(error_message, err)
            else:
                raise BackendError(error_message, err)

        except psycopg.Error as err:

            # if we've been constructed using fromConnection...
            if self._dsn is None:
                raise

            self._dbfailures += 1
            if self._dbfailures > self._ERRORS_BEFORE_RECONNECT:
                self._dbfailures = 0
                try:
                    del self._update_cursor
                    del self._conn

                    self.connect()
                except:
                    raise sys.exc_type(sys.exc_value).with_traceback(
                        sys.exc_traceback)

                cursor.execute(query)
            else:
                raise sys.exc_type(sys.exc_value).with_traceback(
                    sys.exc_traceback)

        return cursor
Example #5
0
 def do_GET(self):
   try:
     if self.path.startswith("/favartist"):
         o=urlparse.urlparse(self.path)
         getvars=urlparse.parse_qs(o.query)
         name=str(getvars['name'][0])
         zipcode=int(getvars['zipcode'][0])
     
         try:
             self.send_response(200)
             self.send_header('Content-type','application/json')
             self.end_headers()
             #name=str(getvars['name'][0])
             #zipcode=int(getvars['zipcode'][0])
             #self.wfile.write('hi',name,zipcode)
             arid=fetchdetails(self,name,zipcode)
             #self.wfile.write(r)
             r1=fetchevent(self,name,zipcode,arid)
             if r1 is 0:
                 self.wfile.write('No events found !!!')
                 #sys.exit()
         except ArithmeticError:
             e=sys.exc_type()
             self.send_error(404,'Error')
             sys.exit()
   except:
     self.wfile.write('Error')
Example #6
0
    def execute(self, query, modify=False):
        """
        Run a query on the database connection.

        This function also performs failure accounting and will
        re-connect to the database if a certain threshold has passed.
        """
        if type(query) == UnicodeType:
            query = query.encode(self.backend_encoding())            
        try:
            cursor = orm2.datasource.datasource_base.execute(self, query,
                                                             modify)
        except psycopg.ProgrammingError as err:
            # In any case rollback the current transaction.
            # For one thing to get rid of that stupid "current transaction is
            # aborted, commands ignored until end of transaction block"
            self.rollback()
            
            error_message = str(err)
            if "duplicate key" in error_message:
                raise DuplicateKey(error_message, err)
            else:
                raise BackendError(error_message, err)
            
        except psycopg.Error as err:

            # if we've been constructed using fromConnection...
            if self._dsn is None:
                raise
            
            self._dbfailures += 1
            if self._dbfailures > self._ERRORS_BEFORE_RECONNECT:
                self._dbfailures = 0
                try:
                    del self._update_cursor
                    del self._conn
                    
                    self.connect()
                except:
                    raise sys.exc_type(sys.exc_value).with_traceback(sys.exc_traceback)
                
                cursor.execute(query)
            else:
                raise sys.exc_type(sys.exc_value).with_traceback(sys.exc_traceback)
            
        return cursor 
Example #7
0
    def run(self):
        while not self.quitting:
            queueObj = self.output_queue.get()
            if queueObj == "quit":
                self.quit()

            try:
                self.report.add(queueObj)
            except Exception, detail:
                # FIXME: log this when we get a logger? -akl
                print _("Exception: %s") % detail
                print sys.exc_type()
                print traceback.print_tb(sys.exc_info()[2])
                #                self.output_queue.task_done()
                self.quit()
                raise
            #            self.write(queueObj)
            # somewhere in here, we return the data to...?
            self.output_queue.task_done()
Example #8
0
def main():
    get_song_only, file_name, store_dir, links = get_args()
    if store_dir is None:
        store_dir = 'Downloaded'
    ''' Get urls input directly from CLI '''
    if links:
        try:
            if get_song_only:
                for url in links:
                    download_song(url, store_dir)
            else:
                for url in links:
                    download_album(url, store_dir)
        except KeyboardInterrupt as e:
            print "OK, terminating..."
            sys.exit(1)
        except:
            print "Unexpected error: ", sys.exc_type()[0]
            raise
    ''' Get urls from file '''
    if file_name:
        try:
            with open(file_name) as f:
                if get_song_only:
                    for url in [line.strip('\n') for line in f]:
                        download_song(url, store_dir)
                else:
                    for url in [line.strip('\n') for line in f]:
                        download_album(url, store_dir)
        except IOError as e:
            print "I/O error '{0}' : {1}".format(e.filename, e.strerror)
        except KeyboardInterrupt as e:
            print "OK, terminating..."
            sys.exit(1)
        except:
            print "Unexpected error: ", sys.exc_type()[0]
            raise
Example #9
0
def attemptConnection(ssh_job):
    # ssh_job is a SshJob object

    if ssh_job.ip != "":
        try:
            ssh = paramikoConnect(ssh_job)
            if type(ssh) == type(
                ""
            ):  # If ssh is a string that means the connection failed and 'ssh' is the details as to why
                ssh_job.command_output = ssh
                ssh_job.connection_result = False
                return
            command_output = []
            executeCommands(transport=ssh, rho_commands=ssh_job.rho_cmds)
            ssh.close()

        except Exception, detail:
            # Connection failed
            print _("Exception: %s") % detail
            print sys.exc_type()
            print sys.exc_info()
            print traceback.print_tb(sys.exc_info()[2])
            ssh_job.connection_result = False
            ssh_job.command_output = detail
Example #10
0
def __exerr(text):
    raise sys.exc_type(sys.exc_value)
    __err(text + ": »%s« (%s)" % (sys.exc_type, sys.exc_value))