(self, data_dir)
return sample_id
@param: exe: path to the binary file
            @return: the sample id
def insert_sample(self, data_dir):
        """ @param: exe: path to the binary file
            @return: the sample id """
        data = open(os.path.join(data_dir, "sample.xml")).read()
        logging.debug("Load the sample XML file")
        doc = xmltodict.parse(data) # Convert XML data into a dictionary

        cur = self.conn.cursor()
        try:
            sample = doc['sample']

            if sample['pin_param']:
                pin_param = sample['pin_param']
            else:
                pin_param = ""

            cur.execute("INSERT INTO sample (filename, md5, insert_at, pin_param) "+\
                    "VALUES (%s, %s, NOW(), %s)",
                (sample['filename'], sample['md5'], pin_param))

            # Warning find a better way to get the last insert element id
            cur.execute("SELECT id FROM sample WHERE md5=%s ORDER BY id DESC", (sample['md5'],))

            sample_id = int(cur.fetchone()[0])
            logging.info("Sample id %d", sample_id)

        except psycopg2.ProgrammingError as e:
            error_str = psycopg2.errorcodes.lookup(e.pgcode)
            logging.debug("psycopg2.ProgrammingError: %s", error_str)
            self.conn.rollback()
            raise MalwasmExceptDb(e.__str__())
        finally:
            cur.close()

        return sample_id
def insert_sample ( self , data_dir ) : data = open ( os . path . join ( data_dir , "sample.xml" ) ) . read ( ) logging . debug ( "Load the sample XML file" ) doc = xmltodict . parse ( data ) # Convert XML data into a dictionary cur = self . conn . cursor ( ) try : sample = doc [ 'sample' ] if sample [ 'pin_param' ] : pin_param = sample [ 'pin_param' ] else : pin_param = "" cur . execute ( "INSERT INTO sample (filename, md5, insert_at, pin_param) " + "VALUES (%s, %s, NOW(), %s)" , ( sample [ 'filename' ] , sample [ 'md5' ] , pin_param ) ) # Warning find a better way to get the last insert element id cur . execute ( "SELECT id FROM sample WHERE md5=%s ORDER BY id DESC" , ( sample [ 'md5' ] , ) ) sample_id = int ( cur . fetchone ( ) [ 0 ] ) logging . info ( "Sample id %d" , sample_id ) except psycopg2 . ProgrammingError as e : error_str = psycopg2 . errorcodes . lookup ( e . pgcode ) logging . debug ( "psycopg2.ProgrammingError: %s" , error_str ) self . conn . rollback ( ) raise MalwasmExceptDb ( e . __str__ ( ) ) finally : cur . close ( ) return sample_id