-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add search to current VM Tab #11
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Glade backup file | ||
*.glade~ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
watchdog = "*" | ||
pyxdg = "*" | ||
pygobject = "*" | ||
gbulb = "*" | ||
qubesadmin = "*" # install this manually, or use the following | ||
# qubesadmin = {git = "https://github.com/QubesOS/qubes-core-admin-client"} | ||
thefuzz = "*" | ||
|
||
[dev-packages] | ||
pytest = "*" | ||
# pytest-asyncio = "*" | ||
pylint = "*" | ||
|
||
[requires] | ||
python_version = ">=3.8" |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
asyncio_mode=strict |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .appmenu import main | ||
|
||
if __name__ == "__main__": | ||
main() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No newline at the end of file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,23 +264,23 @@ def exit_app(self): | |
task.cancel() | ||
|
||
|
||
from .tests.mock_app import new_mock_qapp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mocking should not happen in the application code itself, but exclusively in the tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to run the app in dom0, and I need a way to run the app. This feature is off by default: https://github.com/QubesOS/qubes-desktop-linux-menu/pull/11/files#diff-609223c61e23f236f844ac3294812b922d4d09f34be6c552c7b6d43dd5c21d4bR41 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then, create a file in |
||
import os | ||
|
||
|
||
def main(): | ||
""" | ||
Start the menu app | ||
""" | ||
|
||
qapp = qubesadmin.Qubes() | ||
if "QUBES_MENU_TEST" in os.environ: | ||
qapp = new_mock_qapp(qapp) | ||
qapp.domains[qapp.local_name] = qapp.domains['dom0'] | ||
dispatcher = qubesadmin.events.EventsDispatcher(qapp) | ||
app = AppMenu(qapp, dispatcher) | ||
app.run(sys.argv) | ||
|
||
if f'--{constants.RESTART_PARAM_LONG}' in sys.argv or \ | ||
f'-{constants.RESTART_PARAM_SHORT}' in sys.argv: | ||
sys.argv = [x for x in sys.argv if x not in | ||
(f'--{constants.RESTART_PARAM_LONG}', | ||
f'-{constants.RESTART_PARAM_SHORT}')] | ||
app = AppMenu(qapp, dispatcher) | ||
app.run(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,13 @@ | |
""" | ||
Helper class that manages all events related to .desktop files. | ||
""" | ||
import pyinotify | ||
import logging | ||
import asyncio | ||
import os | ||
import shlex | ||
|
||
from watchdog.observers import Observer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? In what ways is watchdog better than pyinotify? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pyinotify is using |
||
from watchdog.events import FileSystemEventHandler | ||
import xdg.DesktopEntry | ||
import xdg.BaseDirectory | ||
import xdg.Menu | ||
|
@@ -125,6 +127,39 @@ def is_qubes_specific(self): | |
return 'X-Qubes-VM' in self.categories | ||
|
||
|
||
|
||
class FileChangeHandler(FileSystemEventHandler): | ||
def __init__(self, manager: 'DesktopFileManager'): | ||
self.manager = manager | ||
super().__init__() | ||
|
||
def try_load(self, filename): | ||
try: | ||
self.manager.load_file(filename) | ||
except FileNotFoundError: | ||
self.manager.remove_file(filename) | ||
|
||
def on_created(self, event): | ||
"""On file create, attempt to load it. This can lead to spurious | ||
warnings due to 0-byte files being loaded, but in some cases | ||
is necessary to correctly process files.""" | ||
self.try_load(event.src_path) | ||
|
||
def on_deleted(self, event): | ||
""" | ||
On file delete, remove the tile and all its children menu entries | ||
""" | ||
self.manager.remove_file(event.src_path) | ||
|
||
def on_modified(self, event): | ||
"""On modify, simply attempt to load the file again.""" | ||
self.try_load(event.src_path) | ||
|
||
def on_moved(self, event): | ||
self.manager.remove_file(event.src_path) | ||
self.try_load(event.dest_path) | ||
|
||
|
||
class DesktopFileManager: | ||
""" | ||
Class that loads, caches and observes changes in .desktop files. | ||
|
@@ -133,40 +168,10 @@ class DesktopFileManager: | |
Path(xdg.BaseDirectory.xdg_data_home) / 'applications', | ||
Path('/usr/share/applications')] | ||
|
||
# pylint: disable=invalid-name | ||
class EventProcessor(pyinotify.ProcessEvent): | ||
"""pyinotify helper class""" | ||
def __init__(self, parent): | ||
self.parent = parent | ||
super().__init__() | ||
|
||
def process_IN_CREATE(self, event): | ||
"""On file create, attempt to load it. This can lead to spurious | ||
warnings due to 0-byte files being loaded, but in some cases | ||
is necessary to correctly process files.""" | ||
try: | ||
self.parent.load_file(event.pathname) | ||
except FileNotFoundError: | ||
self.parent.remove_file(event.pathname) | ||
|
||
def process_IN_DELETE(self, event): | ||
""" | ||
On file delete, remove the tile and all its children menu entries | ||
""" | ||
self.parent.remove_file(event.pathname) | ||
|
||
def process_IN_MODIFY(self, event): | ||
"""On modify, simply attempt to laod the file again.""" | ||
try: | ||
self.parent.load_file(event.pathname) | ||
except FileNotFoundError: | ||
self.parent.remove_file(event.pathname) | ||
|
||
def __init__(self, qapp): | ||
self.qapp = qapp | ||
self.watch_manager = None | ||
self.notifier = None | ||
self.watches = [] | ||
self.observer = None | ||
self._callbacks: List[Callable] = [] | ||
|
||
# directories used by Qubes menu tools, not necessarily all possible | ||
|
@@ -273,18 +278,12 @@ def _initialize_watchers(self): | |
""" | ||
Initialize all watcher entities. | ||
""" | ||
self.watch_manager = pyinotify.WatchManager() | ||
event_handler = FileChangeHandler(self) | ||
observer = Observer() | ||
|
||
# pylint: disable=no-member | ||
mask = pyinotify.IN_CREATE | pyinotify.IN_DELETE | pyinotify.IN_MODIFY | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
self.notifier = pyinotify.AsyncioNotifier( | ||
self.watch_manager, loop, | ||
default_proc_fun=DesktopFileManager.EventProcessor(self)) | ||
self.observer = observer | ||
|
||
for path in self.desktop_dirs: | ||
self.watches.append( | ||
self.watch_manager.add_watch( | ||
str(path), mask, rec=True, auto_add=True)) | ||
observer.schedule(event_handler, str(path), recursive=True) | ||
|
||
observer.start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be added to git.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
.gitignore
is used to ignore build files and temporary files.