Python Forum
Looking for advice about "registry" implementation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looking for advice about "registry" implementation
#1
I'm working on a plugin for one program and need to implement sort of "registry". In this registry I want to store objects, created by my plugin and also allow other plugins to add/remove objects to/from this registry.

Now, I'm using following approach. In the __init__.py of my plugin I have a list variable and set of functions to add/remove items to the list. Plugins, which want to add items to my registry need to import my module and call corresponding functions. Here is simplified code

In the my __init__.py
registry = []

def addToRegistry(toAdd):
    for item in registry:
        if item.name == toAdd.name and item.group == toAdd.group:
            return
    registry.append(toAdd)


def removeFromRegistry(toRemove):
    for item in registry[::-1]:
        if item.name == toRemove.name and item.group == toRemove.group:
            registry.remove(toRemove)


def addDirectory(folder):
    for d in os.listdir(folder):
        obj = fromFile(os.path.join(folder, d, "object.yaml"))
        if obj:
            addToRegistry(obj)


def removeDirectory(folder):
    for d in os.listdir(folder):
        obj = fromFile(os.path.join(folder, d, "object.yaml"))
        if obj:
            removeFromRegistry(obj)
In other plugins I use this code to add/remove data to/from "registry"

    try:
        from myplugin import addDirectory
        addDirectory(folder)
    except:
        pass

    ...
    try:
        from myplugin import removeDirectory
        removeDirectory(folder)
    except:
        pass
Maybe there are some other solutions? I was thinking about creating singleton registry class but not sure how flexible such solution will be in my case. Any advice is welcome.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to add Python folder in Windows Registry ? Touktouk 1 277 Feb-20-2024, 01:04 PM
Last Post: DeaD_EyE
  Read complete windows registry? fredep57 3 954 Mar-15-2023, 08:14 PM
Last Post: buran
  How to add new registry key shlomi27 3 10,329 Feb-04-2021, 05:45 PM
Last Post: reidnax
  Automatic registering python to registry kozaizsvemira 1 2,199 Oct-22-2019, 11:23 AM
Last Post: kozaizsvemira
  How to ignore - ERROR: The system was unable to find the specified registry key or va asheru93 9 6,668 Feb-04-2019, 06:35 AM
Last Post: asheru93
  Registry Key Access malonn 11 9,402 Jul-26-2018, 09:45 AM
Last Post: gontajones
  Python 3.x Windows 7 registry file associations broken pixhellmann 2 5,074 Sep-12-2017, 09:14 PM
Last Post: Larz60+
  [WinReg]>Issue when reading a registry key CSA75 4 8,937 Mar-28-2017, 03:35 PM
Last Post: CSA75

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020