Exemple #1
0
def load_autosave_item(item_type, item_id):
    item_type_plural = item_types_plural[item_type]

    filename = item_type + "_" + item_id + "_autosave.xml"
    if item_type == "page":
        filename = item_id + "_autosave.xml"

    filepath = item_type_plural + "/" + filename
    if os.path.isfile(filepath):
        FILE = open(filepath, "r")
        contents = FILE.readlines()
        FILE.close()
        contents = "".join(contents)
        item = item_modules[item_type].new(item_id, os.path.getmtime(filepath))
        item.loadfromxml(contents)
        return item
    return None
Exemple #2
0
def load_item_by_id(item_id):
    for item_type in item_types:
        item_type_plural = item_types_plural[item_type]
        if item_type == "page":
            filename = item_type_plural + "/" + item_id + ".xml"
        else:
            filename = item_type_plural + "/" + item_type + "_" + item_id + ".xml"
        if os.path.isfile(filename):
            FILE = open(filename, "rb")
            contents = FILE.readlines()
            FILE.close()
            res = [i.decode("ascii", "ignore") for i in contents]
            contents = "".join(res)
            item = item_modules[item_type].new(item_id, os.path.getmtime(filename))
            item.loadfromxml(contents)
            return (item, item_type)
    return (None, None)
Exemple #3
0
def load_item(item_type, filename):
    item_id = ""
    if item_type == "page":
        item_id = filename.rstrip(".xml")
    else:
        p = re.compile("[\W^_]")
        # (item_type_plural, item_type, item_id) = p.split(filename)[0:3]
        item_id = p.split(filename)[1]

    filename = item_types_plural[item_type] + "/" + filename

    if os.path.isfile(filename):
        FILE = open(filename, "rb")
        contents = FILE.readlines()
        FILE.close()
        res = [i.decode("ascii", "replace") for i in contents]
        contents = "".join(res)
        item = item_modules[item_type].new(item_id, os.path.getmtime(filename))
        item.loadfromxml(contents)
        return item
    return None