Skip to content
/ pyx-sys Public

A library for storage and restore of system state in terms of windows and workspaces

License

Notifications You must be signed in to change notification settings

lmmx/pyx-sys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyx-sys

A library for storage and restore of system state in terms of windows and workspaces

pyxis is the Latin name for the box housing a mariner's compass. This name also relates to the 'box tree' (Buxus sempervirens), whose wood is a source of buxine, a steroid alkaloid used to treat fever. In a similar vein, this library aims to be an elaborate cabinet for process-centric storage of all the components that make up a developer's workflow, to assist in the shutting down of a system in use and restoring its workflow to the same state it was in before.

Requirements

pyx-sys has no external Python dependencies beyond the standard library. You will need:

  • dejsonlz4 (GitHub: avih/dejsonlz4)
    • Used to decompress recovery JSON of Firefox browser state (windows, tabs, recent history)
    • Clone into ~/opt/, symlink the binary at ~/opt/bin/dejsonlz4 and add ~/opt/bin/ to your PATH
  • Linux
    • For use with Mac/Windows, I'd need to see their Firefox sessionstore-backups location
  • X window system (xwininfo must be called to retrieve the list of windows)
  • wmctrl (determine workspaces the windows are in through the window manager)
  • tmux (to obtain listings of terminal windows, any splits/resultant panes, and activities therein)
    • .bashrc must include a wmctrl call to tmux that changes the title of tmux windows upon creation to include the tmux window ID in the gnome-terminal title
if tmux info &> /dev/null; then
  # Tmux server is up, set the terminal title to be the tmux window ID
  TMUX_WINDOW_TITLE=$(tmux run "echo 'Terminal #{window_id}'")
  wmctrl -r :ACTIVE: -N "$TMUX_WINDOW_TITLE";
fi

Next steps

This library has now been reorganised as a package ready for distribution on PyPi, with an entrypoint pyx-space to function as a simple command to execute a relabelling of all workspaces on the system.

The next step is to determine which terminal is where (at what working directory), and what it's running there (i.e. what its PID is, perhaps using psutil). This is available from the list-panes output, which is only semi-finished parsing (I got sidetracked cross-referencing window IDs).

See tm/pane.py where the function list_panes should be finished (it is currently still partly just a copy of list_windows and needs some rethinking), and then added to a Pane object (currently only some of the info retrieved is being used, the pane_id, within the PaneGeom).

There should be enough info at the pane level to create a descriptive summary string indicating the contents of all panes within all terminal windows in tmux, and thus the terminal window can be serialised to a persistent and immediately readable format (desktop workspace names).

This will achieve a large part of pyx-space. Once it's working for human-readable 'storage', we can move onto considering machine-readability and 'restoring' from this representation.

Capabilities

  • Access the xwininfo tree, stored as a WindowTree class with a children attribute that can be walked to enumerate all windows on the system.
    • Modify and activate particular windows in the tree using wmctrl given their ID
    • Cross-reference to the workspace listing
  • Access the wmctrl workspace listing, stored as a WorkspaceTerritory class with a sticky_windows attribute containing the desktop windows and a workspaces attribute, each of which has a windows attribute that lists all windows in that workspace
    • Connect window IDs to those in the WindowTree from xwininfo (differ by one hex digit)
    • Restore windows to a workspace from a pickled WorkspaceTerritory on disk
  • List Firefox window/tab list which can be cross-referenced to the X window/workspace list
    • Store the list of windows/tabs
    • Cross-reference to the X window/workspace list
  • List tmux terminal session list (e.g. which text files are open in vim, command line paths, etc.)
    • cross-reference to X window/workspace list

Rationale

  • In part, the purpose is to catalogue and archive tabs being viewed rather than have this be standalone logs
    • The goal is to feed into these logs and for their use to also be fed from a mobile app
  • Initially however, the goal is to provide session restore for as many components of the developer workflow as possible
    • especially so as to keep associated activities (e.g. doc reading in a browser alongside app development in a terminal) recorded together.
    • Partly this is for session restore, however it may also be used for 'reference restore', i.e. restore at a later date, (for instance when returning to work on a particular feature and opening both the code files and the docs together).

Current workflow

When the module is run (python3 -im pyxsys from the src/ directory), __main__.py calls cli.py and finally adds four local variables to the Python environment:

  • ff_sessionpyxsys.ff.sessionBrowserSession class representing a Firefox browser's state (excluding incognito windows)
  • x_sessionpyxsys.x.treeWindowTree class representing the X window manager's listing of windows in the active session
  • wm_territorypyxsys.wm.territoryWorkspaceTerritory class representing the wmctrl-derived window manager set of workspaces (which I term a 'territory' following the notion of Zubin spaces from the GIS research literature on "spatial information theory")
  • tmux_serverpyxsys.tm.serverTmuxServer class representing the currently running tmux instance, all terminals across all windows/workspaces, and listing relevant information about all panes within them.

They look something like this:

>>> ff_session
BrowserSession of 11 windows, since 2020-03-05 16:48:39.172000
>>> x_session
WindowTree (rooted at RootWindow, id: 0x13f, (has no name))
>>> wm_territory
WorkspaceTerritory of 9 workspaces (30 windows)
>>> tmux_server
TmuxServer of 15 sessions (15 windows)

I'm currently working on finishing off the finer details of these classes, and aim to make them 'work together', i.e. cross-reference their IDs and related activities.

Read more

Sources

About

A library for storage and restore of system state in terms of windows and workspaces

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages