def getpackagesfromfile(path): """Returns all the pseudopackages from the given file in json format Imports the pseudopackages at the given path and returns them in a json type format. The contents of the file are converted to json by the configfilemanager, the real content of the file could be in json, yaml or something similar. arguments: path -- the path to the file containing the pseudopackages execptions: FileNotFoundError -- if the file at the given path is not found this error contains an attribute \"message\", which contains the errormessage UnsupportedFileTypeError -- if the file has the wrong type (extension) this error contains an attribute \"message\", which contains the errormessage and an attribute filename which contains the message """ try: json = configfilemanager.getconfigfromfile(path) except FileNotFoundError as e: e.message = 'File with Packages at path {} could not be found'.format( e.filename) raise return getpackagesfromjson(json)
def fromfile(path, pseudopacks, packagemanagers, name=None): """Returns a TodoList object from the given file The contents of the file are converted to json by the configfilemanager, the real content of the file could be in json, yaml or something similar. arguments: path -- the path to the file containing the collection pseudopacks -- the psudopackages as imported directly from json into python packagemanagers -- a list of PackageManager objects which also specify the order in of which packagemanager to use first name -- the name of the collection in the json, if none is provided, it is assumed that there is only one collection in the json, if not, an error is thrown (default None) execptions: FileNotFoundError -- if the file at the given path is not found this error contains an attribute \"message\", which contains the errormessage UnsupportedFileTypeError -- if the file has the wrong type (extension) this error contains an attribute \"message\", which contains the errormessage and an attribute filename which contains the message KeyError -- if a needed attribute in the json is not found this error contains an attribute \"message\", which contains the errormessage ConfigValueError -- if some attribute in the config has an invalid value this error contains an attribute \"message\", which contains the errormessage """ try: json = configfilemanager.getconfigfromfile(path) except FileNotFoundError as e: e.message = 'File with collections at {} could not be found'.format( path) raise try: collection = Collection.fromjson(json, pseudopacks, \ packagemanagers, name) except (KeyError, ConfigValueError) as e: e.message += 'at {}'.format(path) e.filename = path raise return collection
def multiplefromfile(path, names=None): """Returns multiple TodoList objects from the given file The contents of the file are converted to json by the configfilemanager, the real content of the file could be in json, yaml or something similar. arguments: path -- the path to the file containing the todolists names -- the names of the todolists in the json, if none are provided, all todolists in the json are imported (default None) execptions: FileNotFoundError -- if the file at the given path is not found This error comes from the collections and similar objects which have seperate config files this error contains an attribute \"message\", which contains the errormessage UnsupportedFileTypeError -- if the file has the wrong type (extension) this error contains an attribute \"message\", which contains the errormessage and an attribute filename which contains the message KeyError -- if a needed attribute in the json is not found this error contains an attribute \"message\", which contains the errormessage ConfigValueError -- if some attribute in the config has an invalid value this error contains an attribute \"message\", which contains the errormessage """ try: json = configfilemanager.getconfigfromfile(path) except FileNotFoundError as e: e.message = 'File with todolists at {} could not be found'.format( e.filename) raise try: todolists = TodoList.multiplefromjson(json, names) except (KeyError, ConfigValueError) as e: e.message += ' at {}'.format(path) e.filename = path raise return todolists
def fromfile(path, name=None): """Returns a TodoList object from the given file The contents of the file are converted to json by the configfilemanager, the real content of the file could be in json, yaml or something similar. arguments: path -- the path to the file containing the todolist name -- the name of the todolist in the json, if none is provided, it is assumed that there is only one todolist in the json, if not, an error is thrown (default None) execptions: FileNotFoundError -- if the file at the given path is not found this error contains an attribute \"message\", which contains the errormessage UnsupportedFileTypeError -- if the file has the wrong type (extension) this error contains an attribute \"message\", which contains the errormessage and an attribute filename which contains the message KeyError -- if a needed attribute in the json is not found this error contains an attribute \"message\", which contains the errormessage ConfigValueError -- if some attribute in the config has an invalid value this error contains an attribute \"message\", which contains the errormessage """ try: json = configfilemanager.getconfigfromfile(path) except FileNotFoundError as e: e.message = 'File with todolists at {} could not be found'.format( e.filename) raise try: todolist = fromjson(json) except (KeyError, ConfigValueError) as e: e.message = e.message + ' at {}'.format(path) e.filename = path raise return todolist