예제 #1
0
 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 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 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
예제 #4
0
 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 status():
    '''() -> NoneType
    Prints the current status of the updates, including the following
    relevant information: time of last update, current auto-update settings and
    the number of changes pending to be reviewed.
    '''

    unpack_changes()
    last_update = STORAGE.config_get("last_update")
    repo_url = STORAGE.config_get("repo_url")

    num_changes = len(CHANGES)
    if last_update == "Never":
        print("Last Update: Never" + "\n")
        print("Repo: " + repo_url)
    else:
        print("\nLast Update: " + str(last_update))
        print("Number of proposed changes stored : " + str(num_changes) + "\n")
        print("Repo: " + repo_url)
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 show_all():
    '''() -> NoneType
    Method for showing all proposed changes
    '''

    unpack_changes()
    # sort the list of proposed changes
    i = 1
    while i <= len(CHANGES):
        show_number(i)
        i += 1
    print("\nNumber of changes shown : " + str(len(CHANGES)))
    print("Last update : " + str(STORAGE.config_get("last_update")))
    # to reset last update time to default state ("Never"), and config file in
    # general : STORAGE.clean_config_file()
    print("End.\n")
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 getCurrentBranchNumber():
    """ () -> int
    Return the current branch number, without incrementing it
    """
    return STORAGE.config_get("branch_number") - 1
def getLink():
    """ () -> str
    Return the link of the repository
    """
    return STORAGE.config_get("repo_url")
from subprocess import call
import xml.etree.ElementTree as ET
import data_comparison.proposed_change as PC
import os
import datetime
import storage_manager.storage_manager as STORAGE

# 'static' vars
files = []
direc = "github/open_exoplanet_catalogue"
link = STORAGE.config_get("repo_url")


def getLink():
    """ () -> str
    Return the link of the repository
    """
    return STORAGE.config_get("repo_url")


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 getCurrentBranchNumber():
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")