MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / setup_pager_shared_data

Function setup_pager_shared_data

pager/PagerRagnar.py:29–142  ·  view source on GitHub ↗

Patch shared_data with Pager-specific attributes needed by pager_display.py. Ragnar's shared.py loads PIL Images; the Pager needs file paths instead.

(shared_data)

Source from the content-addressed store, hash-verified

27
28
29def setup_pager_shared_data(shared_data):
30 """Patch shared_data with Pager-specific attributes needed by pager_display.py.
31 Ragnar's shared.py loads PIL Images; the Pager needs file paths instead."""
32
33 currentdir = shared_data.currentdir
34 fontdir = shared_data.fontdir
35 staticpicdir = shared_data.staticpicdir
36 statuspicdir = shared_data.statuspicdir
37
38 # Font paths (pager_display uses pagerctl TTF rendering, not PIL)
39 shared_data.font_arial_path = os.path.join(fontdir, 'Arial.ttf')
40 shared_data.font_viking_path = os.path.join(fontdir, 'Viking.TTF')
41
42 # Status image path (updated by update_ragnarstatus_pager)
43 shared_data.ragnarstatusimage_path = None
44
45 # Static image paths dict (icon_name -> file_path)
46 shared_data.static_images = {}
47 static_names = ['ragnar1', 'port', 'frise', 'target', 'vuln', 'connected',
48 'bluetooth', 'wifi', 'ethernet', 'usb', 'level', 'cred',
49 'attack', 'attacks', 'gold', 'networkkb', 'zombie', 'data', 'money']
50 for name in static_names:
51 path = os.path.join(staticpicdir, f'{name}.bmp')
52 if os.path.exists(path):
53 shared_data.static_images[name] = path
54
55 # Status images dict (b_class -> file_path)
56 shared_data.status_images = {}
57 try:
58 if os.path.exists(shared_data.actions_file):
59 with open(shared_data.actions_file, 'r') as f:
60 actions = json.load(f)
61 for action in actions:
62 b_class = action.get('b_class')
63 if b_class:
64 status_dir = os.path.join(statuspicdir, b_class)
65 image_path = os.path.join(status_dir, f'{b_class}.bmp')
66 if os.path.exists(image_path):
67 shared_data.status_images[b_class] = image_path
68 except Exception as e:
69 logger.error(f"Error loading status image paths: {e}")
70
71 # Image series paths for animations (b_class -> list of file paths)
72 shared_data.pager_image_series = {}
73 for status in shared_data.status_list:
74 shared_data.pager_image_series[status] = []
75 status_dir = os.path.join(statuspicdir, status)
76 if os.path.isdir(status_dir):
77 for image_name in sorted(os.listdir(status_dir)):
78 if image_name.endswith('.bmp') and re.search(r'\d', image_name):
79 image_path = os.path.join(status_dir, image_name)
80 shared_data.pager_image_series[status].append(image_path)
81
82 # Current animation frame path
83 shared_data.current_image_path = None
84
85 # Monkey-patch update_ragnarstatus to use file paths
86 original_update = shared_data.update_ragnarstatus

Callers 1

PagerRagnar.pyFile · 0.85

Calls 4

errorMethod · 0.80
appendMethod · 0.80
infoMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected