brightway-lca / brightway2-data

Tools for the management of inventory databases and impact assessment methods. Part of the Brightway LCA framework.
https://docs.brightway.dev/
BSD 3-Clause "New" or "Revised" License
8 stars 21 forks source link

allow _read only_ access to projects #39

Closed aleksandra-kim closed 8 years ago

aleksandra-kim commented 8 years ago

Original report by Tomas Navarrete Gutierrez (Bitbucket: tomas_navarrete, ).


It would be useful to have a way to specify that we want to access a project in "read only" mode, so that a write lock does not get created automatically.

aleksandra-kim commented 8 years ago

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


The whole way of choosing the current project is pretty crap. How was this not a function from the beginning?

What do you think about the following:

#!python

class ProjectManager:
    @property
    def current(self):
        return self._project

    def set_current(self, name, writable=True):
        self._project = project

        if writable:
            self._lock = InterProcessLock(os.path.join(self.dir, "write-lock"))
            self.read_only = not self._lock.acquire(timeout = 0.05)
        else:
            self.read_only = True

I don't know if .set_current() is better than .set()... but I am totally OK with making choosing a project an explicit function, and then being able to pass writable=False.

aleksandra-kim commented 8 years ago

Original comment by Tomas Navarrete Gutierrez (Bitbucket: tomas_navarrete, ).


I vote for set_current()

For the rest, it looks good to me.

aleksandra-kim commented 8 years ago

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


Change how to set projects. Fixes #39

aleksandra-kim commented 8 years ago

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


Fix is in version 2.2, on pypi now.