PHP 7.4.33
Preview: pickle_database.py Size: 1.34 KB
/home/godevadmin/public_html/upload_images/home/000~ROOT~000/lib/fm-agent/library/pickle_database.py

import pickle
import logging
import traceback


class PickleDatabase(object):
    """This object is a wrapper to access and handle our
    local pickle file. We'll use this pickle file as a sort of
    database for storing schedules and other info for the agent."""

    def __init__(self, file_path):
        self.file_path = file_path
        try:
            self.data = pickle.load(open(file_path, "rb"))
        except Exception:
            # If something went wrong, the data is either corrupted or missing.
            log = logging.getLogger(self.__class__.__name__)
            log.warn(
                "Unable to open database {}, creating an empty one".format(
                    self.file_path
                )
            )
            self.data = {}
            open(self.file_path, "wb")  # Create the DB file if it doesn't exist
            log.info("Database created: %s" % self.file_path)

    def save(self):
        # Dump current contents of our dict into the pickle file
        pickle.dump(self.data, open(self.file_path, "wb"))

    def __getitem__(self, key):
        return self.data[key]

    def __setitem__(self, key, value):
        self.data[key] = value
        # Save our newly updated dictionary
        self.save()

    def __repr__(self):
        return str(self.data)

    def __contains__(self, key):
        return key in self.data

Directory Contents

Dirs: 1 × Files: 23

Name Size Perms Modified Actions
- drwxr-xr-x 2025-06-19 05:08:01
Edit Download
107.89 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
110 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download
9.19 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
14.82 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.17 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
807 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download
3.54 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.12 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.99 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
16.17 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.97 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.96 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
4.25 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
3.62 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.34 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
5.32 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
11.69 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
872 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download
874 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.99 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
3.23 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.48 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
0 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).