def file_to_properties(extension, rel_exec_path='/src/main/processor', rel_property_path='/properties/'): current_path = os.path.dirname(os.path.realpath(__file__)) setup_file = current_path.replace(rel_exec_path, rel_property_path) setup_file += extension properties = property_reader.make_dictionary(setup_file) return properties
def get_matching_files(properties): """Walks a specified path and finds files that match the pattern. The passed properties file must contain a source_path, and will look for files that match the pattern starts_with, ends_with, or contains. The function will attempt to read a properties file or can take a dictionary with k,v pairs. """ if type(properties) is not dict: try: properties = property_reader.make_dictionary(properties) except: return None try: pattern_matcher = pattern_match_closure(properties) return_files = [] for parent, children, files in os.walk(properties['source_path'][0]): get_full_path = full_path_closure(parent) match_files = filter(lambda item: pattern_matcher(item), files) return_files += map(get_full_path, match_files) return return_files except: return None
return "Cannot remove specified database." def mongo_add_geojson_index(collection, field): """Adds a geojson index using GEOSPHERE to the specified field. Returns the new indexed field. """ geo_index = collection.create_index([(field, GEOSPHERE)]) return geo_index if __name__ == '__main__': real_path = os.path.dirname(os.path.realpath(__file__)) real_path += "/test/ghcnm.metadata.headers" print real_path, 'realest of the paths' properties = property_reader.make_dictionary(real_path) print properties, '(properties)' records = record_reader.get_records_as_tuples(properties) db_name = "test_connection" print db_name, ' (collection name)' connection = mongo_get_connection(db_name) print connection collection = mongo_get_collection(connection, "Station") print collection print records[0], ' (trying to insert this)' insert_one_test = mongo_insert_one(collection, records[0]) print insert_one_test, 'insert one results' print collection.count(), 'first count' insert_all_test = mongo_insert_many(collection, records) print collection.count(), 'second count' all_records = mongo_find_records(collection)