def clearblacklist(): '''() -> NoneType Method for clearing declined blacklist of proposed changes ''' STORAGE.config_set("black_list", []) print("Done.")
def deny_range(start, end): '''(int, int) -> NoneType or (str, str) -> NoneType, where str in [s,e] Method for denying a range of proposed changes between start and end Returns NoneType ''' global CHANGES unpack_changes() # sort the list of proposed changes if isinstance(start, str) and start.lower() == "s": start = 0 elif isinstance(start, str) and start.lower() == "e": start = len(CHANGES) if isinstance(end, str) and end.lower() == "e": end = len(CHANGES) elif isinstance(end, str) and end.lower() == "s": end = 0 bothInts = isinstance(start, int) and isinstance(end, int) validRange = 0 <= start <= len(CHANGES) and 0 <= end <= len(CHANGES) if (bothInts and validRange): black_list = STORAGE.config_get("black_list") for i in range(end, start - 1, -1): black_list.append(CHANGES.pop(i - 1)) # update the blacklist STORAGE.config_set("black_list", black_list) # update the changes list in memory STORAGE.write_changes_to_memory(CHANGES) else: print("Invalid range")
def test_config_set_get_simple(self): STORAGE.CONFIG_PATH = "storage_manager_test_files/mock_config_file" STORAGE.clean_config_file() STORAGE.config_set("key1", "TEST string") STORAGE.config_set("key2", [1, 14, 44]) self.assertEqual(STORAGE.config_get("key1"), "TEST string") self.assertEqual(STORAGE.config_get("key2"), [1, 14, 44]) STORAGE.clean_config_file()
def getNextBranchNumber(): """ () -> int Return the next valid branch number, and increment the next branch so it is valid still """ branch_number = STORAGE.config_get("branch_number") STORAGE.config_set("branch_number", branch_number + 1) return branch_number
def test_config_set_get_object(self): STORAGE.CONFIG_PATH = "storage_manager_test_files/mock_config_file" STORAGE.clean_config_file() p = Planet.Planet("a") p.lastupdate = "16/11/20" test_object = Change.Addition("origin", p) STORAGE.config_set("key", test_object) retrieved = STORAGE.config_get("key") self.assertEqual(retrieved.__class__.__name__, "Addition") self.assertEqual(retrieved.origin, "origin")
def deny_all(): '''() -> NoneType Method for declining all proposed changes. Returns NoneType ''' unpack_changes() # add all currently pending changes to blacklist black_list = STORAGE.config_get("black_list") black_list.extend(CHANGES) # write black list to memory STORAGE.config_set("black_list", black_list) # clear the list of currently pending changes STORAGE.write_changes_to_memory([]) print("Done.")
def deny_number(n): '''(int) -> NoneType Method for declining a specific proposed changed, the one designated by 'n' Returns NoneType ''' unpack_changes() if n > 0 and n <= len(CHANGES): # if given number is within the range, add the n-th change to black # list and pop it from thelist of changes black_list = STORAGE.config_get("black_list") black_list.append(CHANGES.pop(n - 1)) # update the blacklist STORAGE.config_set("black_list", black_list) # update the changes list in memory STORAGE.write_changes_to_memory(CHANGES) print("Done.") else: print("Out of range.")
def clearrepo(): '''() -> NoneType ''' STORAGE.config_set("repo_url", STORAGE.DEFAULT_REPO_URL)
def setrepo(repo_name): '''(str) -> NoneType ''' STORAGE.config_set("repo_url", repo_name)
def update(): '''() -> NoneType Method for updating system from remote databases and generating proposed changes. Network connection required. Returns NoneType ''' # postpone all currently pending changes STORAGE.write_changes_to_memory([]) # open exoplanet catalogue global CHANGES CHANGES = [] try: XML.downloadXML(XML_path) except urllib.error.URLError: print("No internet connection\n") return OEC_lists = XML.buildSystemFromXML(XML_path) OEC_systems = OEC_lists[0] OEC_stars = OEC_lists[1] OEC_planets = OEC_lists[2] # delete text files from previous update clean_files() # targets: # Saves nasa database into a text file named nasa_file NASA_getter = API.apiGet(NASA_link, nasa_file) try: NASA_getter.getFromAPI("&table=planets") # NASA_getter.getFromAPI("") except (TimeoutError, API.CannotRetrieveDataException) as e: print("NASA archive is unreacheable.\n") except (urllib.error.URLError): print("No internet connection.\n") # Saves exoplanetEU database into a text file named exo_file exoplanetEU_getter = API.apiGet(exoplanetEU_link, EU_file) try: exoplanetEU_getter.getFromAPI("") except (TimeoutError, API.CannotRetrieveDataException) as e: print("exoplanet.eu is unreacheable.\n") except (urllib.error.URLError): print("No internet connection.\n") # build the dict of stars from exoplanet.eu EU_stars = CSV.buildDictStarExistingField(EU_file, "eu") # build the dict of stars from NASA NASA_stars = CSV.buildDictStarExistingField(nasa_file, "nasa") # build the dictionary of stars from Open Exoplanet Catalogue OEC_stars = XML.buildSystemFromXML(XML_path)[4] # clean both dictionaries for d in [EU_stars, NASA_stars]: for key in d: if d.get(key).__class__.__name__ != "Star": d.pop(key) # retrieve the blacklist from memory black_list = STORAGE.config_get("black_list") # add chages from EU to the list (if they are not blacklisted by the user) for key in EU_stars.keys(): if key in OEC_stars.keys(): Comp_object = COMP.Comparator(EU_stars.get(key), OEC_stars.get(key), "eu") LIST = Comp_object.proposedChangeStarCompare() for C in LIST: if (not C in black_list) and (not C in CHANGES): CHANGES.append(C) # add chages from NASA to the list for key in NASA_stars.keys(): if key in OEC_stars.keys(): Comp_object = COMP.Comparator(NASA_stars.get(key), OEC_stars.get(key), "nasa") LIST = Comp_object.proposedChangeStarCompare() for C in LIST: if (not C in black_list) and (not C in CHANGES): CHANGES.append(C) # sort the list of proposed changes CHANGES = PC.merge_sort_changes(CHANGES) # write the list of proposed changes to memory using storage_manager STORAGE.write_changes_to_memory(CHANGES) # calculate current time curr_time = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') STORAGE.config_set("last_update", curr_time) print("\nNumber of differences discovered : " + str(len(CHANGES))) print("Current time : " + curr_time) print("Update complete.\n")