def test_queries_while_batch_insert(self): self.assertTrue(os.path.exists(cfg.generated_ttl_dir())) for root, dirs, files in os.walk(cfg.generated_ttl_dir()): for ttl_file in filter(lambda f: f.endswith(".ttl"), files): full_path = os.path.abspath(os.path.join(root, ttl_file)) print full_path counter = 0 current_batch = "" for line in open(full_path): if (line.startswith("@prefix")): continue current_batch += line if len(line) > 1 and line[:-1].endswith('.'): counter += 1 if counter >= BATCH_SIZE: query = "INSERT {" + current_batch + "}" token = self.tracker.batch_update( query, timeout=20000, result_handler=self.batch_success_cb, error_handler=self.batch_failed_cb) self.run_a_query() counter = 0 current_batch = "" self.batch_counter += 1 GObject.timeout_add_seconds(2, self.run_a_query) # Safeguard of 60 seconds. The last reply should quit the loop GObject.timeout_add_seconds(60, self.timeout_cb) self.main_loop.run()
def __populate_database(self): self.assertTrue(os.path.exists(cfg.generated_ttl_dir())) for ttl_file in [ "010-nco_EmailAddress.ttl", "011-nco_PostalAddress.ttl", "012-nco_PhoneNumber.ttl", "014-nco_ContactEmail.ttl", "015-nco_ContactCall.ttl", "018-nco_PersonContact.ttl", "012-nco_PhoneNumber.ttl", "016-nco_ContactIM.ttl" ]: full_path = os.path.abspath( os.path.join(cfg.generated_ttl_dir(), ttl_file)) print full_path self.tracker.get_tracker_iface().Load('(s)', "file://" + full_path, timeout=30000)
def test_queries_while_import(self): assert os.path.isdir(cfg.generated_ttl_dir()) for root, dirs, files in os.walk(cfg.generated_ttl_dir()): for ttl_file in [f for f in files if f.endswith(".ttl")]: full_path = os.path.abspath(os.path.join(root, ttl_file)) self.files_counter += 1 self.tracker.load("file://" + full_path, timeout=30000, result_handler=self.loaded_success_cb, error_handler=self.loaded_failed_cb, user_data=full_path) GLib.timeout_add_seconds(2, self.run_a_query) # Safeguard of 60 seconds. The last reply should quit the loop # It doesn't matter if we didn't import all of the files yet. GLib.timeout_add_seconds(60, self.timeout_cb) self.main_loop.run()