def connect(table_name, dates_with_attributes):
    connection = get_connection('anki_user', 'ankireddy', 'localhost', 'dates',
                                5432)
    cursor = get_cursor(connection)
    ins_query = get_insert_query(table_name)
    insert_data(connection, cursor, ins_query, dates_with_attributes)
    connection.close()
Exemple #2
0
 def assertSizes(self, name):
     """ Compare size of records using clang sizeof versus python sizeof.""" 
     target = get_cursor(self.parser.tu, name)
     self.assertTrue(target is not None, '%s was not found in source'%name )
     _clang = target.type.get_size()
     _python = ctypes.sizeof(getattr(self.namespace,name))
     self.assertEquals( _clang, _python, 
         'Sizes for target: %s Clang:%d Python:%d flags:%s'%(name, _clang, _python, self.parser.flags))
Exemple #3
0
 def assertOffsets(self, name):
     """ Compare offset of records' fields using clang offsets versus 
     python offsets."""
     target = get_cursor(self.parser.tu, name).type.get_declaration()
     self.assertTrue(target is not None, '%s was not found in source'%name )
     members = [c.displayname for c in target.get_children() if c.kind.name == 'FIELD_DECL']
     _clang_type = target.type
     _python_type = getattr(self.namespace,name)
     # Does not handle bitfield
     for member in members:
         _c_offset = _clang_type.get_offset(member)
         _p_offset = 8*getattr(_python_type, member).offset
         self.assertEquals( _c_offset, _p_offset, 
             'Offsets for target: %s.%s Clang:%d Python:%d flags:%s'%(
                 name, member, _c_offset, _p_offset, self.parser.flags))
Exemple #4
0
                print "ERROR: Skipped placemark due to parsing error: ", e
    except Exception as e:
        print "ERROR: Skipped corrupted file " + path + ": ", e

    return trips


def upload_trip(tripdata, cur):
    """Uploads a trip to the database.
	Args:
		tripdata: dictonary containing trip information"""

    #print tripdata
    cur.execute(
        "INSERT INTO %(trip)t (user_id, start_time, end_time, distance, activity, geom, start_geom, end_geom)\
					 SELECT %(user_id)s, %(start_time)s, %(end_time)s, %(distance)s, %(activity)s,\
					 ST_LineFromText(%(geom)s, 4326), ST_StartPoint(ST_LineFromText(%(geom)s, 4326)), ST_EndPoint(ST_LineFromText(%(geom)s, 4326))",
        tripdata)


if __name__ == '__main__':
    files = glob.glob(KML_DIR + '/*/*.kml')

    print("Creating trips table...")
    with util.get_cursor() as cur:
        cur.execute(open("SQL/create_trip.sql", 'r').read())

    print("Uploading data...")
    pyparade.Dataset(files).flat_map(extract_trips_from_kml).map(
        upload_trip, util.get_cursor).collect(description="Uploading trips")
};""" % (self.__get_declaration(), methods)
        return class_def
        


if __name__ == '__main__':
    if len(sys.argv) < 3:
        print "Please input .cpp file and class."
        sys.exit(1)
    
    source_dir = os.path.join(os.path.dirname(__file__), 'test_data')
    src = os.path.join(source_dir, sys.argv[1])
    class_to_extract = sys.argv[2]

    tu = TranslationUnit.from_source(src)
    class_cursor = get_cursor(tu, class_to_extract)
    
    if class_cursor is None or \
            class_cursor.kind != CursorKind.CLASS_DECL or \
            not class_cursor.is_definition():
        print "source file %s does not contain any class" % src
        sys.exit(1)

    member_method_cursors = \
        get_cursors_if(class_cursor,
                       lambda c: c.kind == CursorKind.CXX_METHOD)

    for m in member_method_cursors:
        print "name of the member:", m.spelling
        print "displayname:", m.displayname
        print "kind:", m.kind.name