parameters: (self, data_dir)
return_statement: return sample_id
docstring: @param: exe: path to the binary file
              @return: the sample id
function: 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
function_tokens: 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