refactor: extract the shared foundation into an installable library
The single file extension carried 260 lines of infrastructure under its
four Nemo providers: the config file with live reload, the git query
layer, the TTL cache with .git watching, and repository detection. Any
second extension wanting repository awareness had to repeat all of it.
Move that foundation into a nemoRepoCore package with a deliberate plugin
API rather than whatever the providers happened to leave behind:
* Config gains layered defaults, so a plugin registers its own keys and
an empty config file is still a working one
* RepoInfo gains a root, a named last commit tuple and a summary string
* RepoCache gains refresh, invalidate and an invalidation callback
* discovery separates the cheap root check used on every drawn folder
from the upward walk used by on demand work such as menus
* nemoFiles collapses the uri scheme and directory guards every
provider was repeating
* launchers learn the per emulator flag for running a command
* version negotiation lets a plugin state the core it was built for
The config file moves to nemo-repo-core.json and is seeded from the old
nemo-repo-emblems.json when one exists, so no key changes name and
nothing needs editing by hand.
This commit is contained in:
1 parent
d81b502300
commit
4ae3a496af
19 files changed
+871
-708
No files matched your search
@@ -0,0 +1,36 @@
|
||||
"""Turning the Nemo.FileInfo objects handed to a provider into local paths.
|
||||
|
||||
Every provider needs the same two guards before it can do anything useful:
|
||||
the item must live on the local filesystem, and for repository work it must
|
||||
be a directory. Getting either wrong means running git against a path that
|
||||
does not exist, or against an ftp:// URI.
|
||||
"""
|
||||
|
||||
from gi.repository import GLib
|
||||
|
||||
|
||||
def localPath(nemoFile):
|
||||
"""Filesystem path for `nemoFile`, or None if it is not a local file."""
|
||||
if nemoFile.get_uri_scheme() != "file":
|
||||
return None
|
||||
try:
|
||||
return GLib.filename_from_uri(nemoFile.get_uri())[0]
|
||||
except GLib.Error:
|
||||
return None
|
||||
|
||||
|
||||
def localDirectoryPath(nemoFile):
|
||||
"""Filesystem path for `nemoFile` when it is a local directory, else None."""
|
||||
if not nemoFile.is_directory():
|
||||
return None
|
||||
return localPath(nemoFile)
|
||||
|
||||
|
||||
def singleLocalDirectory(files):
|
||||
"""Path of the one selected local directory, or None for any other case.
|
||||
|
||||
Property pages and single-target menu items all want exactly this.
|
||||
"""
|
||||
if len(files) != 1:
|
||||
return None
|
||||
return localDirectoryPath(files[0])
|
||||
Reference in new issue
Block a user