mbexe 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mbexe/__init__.py ADDED
@@ -0,0 +1 @@
1
+ # MB Execute - a safe bridge between JavaScript and Python.
mbexe/download.py ADDED
@@ -0,0 +1,226 @@
1
+ # =====================================================
2
+ # MB Execute - download.py (the launcher)
3
+ #
4
+ # Commands (typed in Terminal after "pip3 install mbexe"):
5
+ # mbexe setup makes "MB Execute.app" so websites can open it (mbexe://)
6
+ # mbexe setup --dev PATH (for the developer) run local code from PATH instead
7
+ # mbexe checks for updates, then runs mbexe (startup.py)
8
+ #
9
+ # What "mbexe" does:
10
+ # 1. Ask Firebase for version.json (wait max 3 seconds)
11
+ # 2. Nothing saved yet? download everything (no internet = popup + stop)
12
+ # Newer version live? download into a temp folder, then swap it in
13
+ # (failed = keep the old one and run that)
14
+ # 3. Run startup.py from the saved copy
15
+ # Everything is written to ~/Library/Application Support/MB Execute/mbexe.log
16
+ # =====================================================
17
+
18
+ import os
19
+ import sys
20
+ import json
21
+ import shutil
22
+ import subprocess
23
+ import urllib.request
24
+ from pathlib import Path
25
+ from datetime import datetime
26
+
27
+ LIVE = 'https://my-site-f55c8.web.app/' # where the real code lives (Firebase)
28
+ SUPPORT = Path.home() / 'Library' / 'Application Support' / 'MB Execute'
29
+ CODE = SUPPORT / 'code' # the saved copy of mbexe
30
+ NEW = SUPPORT / 'code.new' # temp folder while updating
31
+ OLD = SUPPORT / 'code.old' # old copy while swapping
32
+ CONFIG = SUPPORT / 'config.json'
33
+ LOG = SUPPORT / 'mbexe.log'
34
+ APP = Path.home() / 'Applications' / 'MB Execute.app'
35
+
36
+
37
+ # ---------- small helpers ----------
38
+ def log(text):
39
+ line = datetime.now().strftime('%H:%M:%S ') + text
40
+ print(line)
41
+ with open(LOG, 'a') as f:
42
+ f.write(line + '\n')
43
+
44
+
45
+ def popup(message):
46
+ """A Mac popup (built into macOS)."""
47
+ script = 'display dialog "%s" with title "MB Execute" buttons {"OK"} default button "OK"' % (
48
+ message.replace('"', '\\"'))
49
+ subprocess.run(['osascript', '-e', script], capture_output=True)
50
+
51
+
52
+ def get(path, timeout):
53
+ """Download one file from Firebase. Gives back the bytes."""
54
+ with urllib.request.urlopen(LIVE + path, timeout=timeout) as r:
55
+ return r.read()
56
+
57
+
58
+ def version_number(v):
59
+ """'1.10' -> (1, 10), so 1.10 counts as newer than 1.9"""
60
+ return tuple(int(x) for x in str(v).split('.'))
61
+
62
+
63
+ def load_json(path):
64
+ try:
65
+ return json.loads(Path(path).read_text())
66
+ except (OSError, ValueError):
67
+ return {}
68
+
69
+
70
+ def safe_name(name):
71
+ """Only simple paths like 'safety/file_rules.py' - no tricks."""
72
+ parts = name.split('/')
73
+ return bool(name) and not name.startswith('/') and '\\' not in name and \
74
+ all(p and p != '..' and not p.startswith('.') for p in parts)
75
+
76
+
77
+ # ---------- updating ----------
78
+ def download_all(info):
79
+ """Download every file in version.json into NEW. Gives back True if all worked."""
80
+ shutil.rmtree(NEW, ignore_errors=True)
81
+ try:
82
+ for name in info['files']:
83
+ if not safe_name(name):
84
+ raise ValueError('bad file name: ' + name)
85
+ target = NEW / name
86
+ target.parent.mkdir(parents=True, exist_ok=True)
87
+ target.write_bytes(get(name, 15))
88
+ return True
89
+ except Exception as e:
90
+ log('download failed: %s' % e)
91
+ shutil.rmtree(NEW, ignore_errors=True)
92
+ return False
93
+
94
+
95
+ def swap_in_new():
96
+ """Put NEW in place of CODE. Either the new one is complete, or the old one stays."""
97
+ shutil.rmtree(OLD, ignore_errors=True)
98
+ if CODE.exists():
99
+ CODE.rename(OLD)
100
+ NEW.rename(CODE)
101
+ shutil.rmtree(OLD, ignore_errors=True)
102
+
103
+
104
+ def update():
105
+ """Gives back True if there's code to run (new or old)."""
106
+ have = load_json(CODE / 'version.json').get('version')
107
+
108
+ try:
109
+ live = json.loads(get('version.json', 3))
110
+ except Exception as e:
111
+ live = None
112
+ log('could not check for updates (%s)' % e.__class__.__name__)
113
+
114
+ if have is None: # nothing saved yet
115
+ if live and download_all(live):
116
+ swap_in_new()
117
+ log('downloaded MB Execute version %s' % live['version'])
118
+ return True
119
+ popup('MB Execute needs the internet the first time. Connect and try again.')
120
+ log('first download failed, stopping')
121
+ return False
122
+
123
+ if live and version_number(live['version']) > version_number(have):
124
+ log('new version %s found (you have %s)' % (live['version'], have))
125
+ if download_all(live):
126
+ swap_in_new()
127
+ log('updated to %s' % live['version'])
128
+ else:
129
+ log('update failed, running old MBEXE version %s' % have)
130
+ elif live:
131
+ log('MB Execute %s is up to date' % have)
132
+ else:
133
+ log('no internet, running saved MBEXE version %s' % have)
134
+ return True
135
+
136
+
137
+ # ---------- commands ----------
138
+ def run():
139
+ SUPPORT.mkdir(parents=True, exist_ok=True)
140
+ LOG.write_text('') # a fresh log every start
141
+ dev = load_json(CONFIG).get('dev_folder')
142
+
143
+ if dev and (Path(dev) / 'startup.py').exists():
144
+ folder = Path(dev)
145
+ log('developer mode: running local code from ' + dev)
146
+ else:
147
+ if not update():
148
+ sys.exit(1)
149
+ folder = CODE
150
+
151
+ # run mbexe; its messages go into the log too
152
+ with open(LOG, 'a') as f:
153
+ result = subprocess.run([sys.executable, '-u', 'startup.py', '--app'],
154
+ cwd=folder, stdout=f, stderr=f)
155
+ sys.exit(result.returncode)
156
+
157
+
158
+ INFO_PLIST = '''<?xml version="1.0" encoding="UTF-8"?>
159
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
160
+ <plist version="1.0">
161
+ <dict>
162
+ <key>CFBundleName</key><string>MB Execute</string>
163
+ <key>CFBundleDisplayName</key><string>MB Execute</string>
164
+ <key>CFBundleIdentifier</key><string>co.mellowblue.mbexecute</string>
165
+ <key>CFBundleVersion</key><string>1.0</string>
166
+ <key>CFBundleExecutable</key><string>MB Execute</string>
167
+ <key>CFBundlePackageType</key><string>APPL</string>
168
+ <key>LSUIElement</key><true/>
169
+ <key>CFBundleURLTypes</key>
170
+ <array>
171
+ <dict>
172
+ <key>CFBundleURLName</key><string>MB Execute link</string>
173
+ <key>CFBundleURLSchemes</key><array><string>mbexe</string></array>
174
+ </dict>
175
+ </array>
176
+ </dict>
177
+ </plist>
178
+ '''
179
+
180
+
181
+ def setup(args):
182
+ SUPPORT.mkdir(parents=True, exist_ok=True)
183
+
184
+ # developer mode: mbexe setup --dev ~/mellowblue/MBEXE
185
+ config = load_json(CONFIG)
186
+ if '--dev' in args:
187
+ i = args.index('--dev')
188
+ folder = Path(args[i + 1]).expanduser().resolve() if i + 1 < len(args) else None
189
+ if not folder or not (folder / 'startup.py').exists():
190
+ print('No startup.py found there. Usage: mbexe setup --dev ~/mellowblue/MBEXE')
191
+ sys.exit(1)
192
+ config['dev_folder'] = str(folder)
193
+ print('Developer mode: MB Execute will run your local code from', folder)
194
+ else:
195
+ config.pop('dev_folder', None)
196
+ CONFIG.write_text(json.dumps(config, indent=2))
197
+
198
+ # build MB Execute.app in ~/Applications
199
+ shutil.rmtree(APP, ignore_errors=True)
200
+ (APP / 'Contents' / 'MacOS').mkdir(parents=True)
201
+ (APP / 'Contents' / 'Info.plist').write_text(INFO_PLIST)
202
+ launcher = APP / 'Contents' / 'MacOS' / 'MB Execute'
203
+ launcher.write_text('#!/bin/zsh\n'
204
+ '# MB Execute.app - runs "mbexe" (download.py)\n'
205
+ 'exec "%s" -m mbexe.download\n' % sys.executable)
206
+ launcher.chmod(0o755)
207
+
208
+ # tell macOS that mbexe:// links belong to this app
209
+ lsregister = ('/System/Library/Frameworks/CoreServices.framework/Frameworks/'
210
+ 'LaunchServices.framework/Support/lsregister')
211
+ subprocess.run([lsregister, '-f', str(APP)], capture_output=True)
212
+
213
+ print('Made', APP)
214
+ print('Done! Websites can now open MB Execute with mbexe:// links.')
215
+
216
+
217
+ def main():
218
+ args = sys.argv[1:]
219
+ if args and args[0] == 'setup':
220
+ setup(args[1:])
221
+ else:
222
+ run()
223
+
224
+
225
+ if __name__ == '__main__':
226
+ main()
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: mbexe
3
+ Version: 0.1.0
4
+ Summary: MB Execute: a safe bridge that lets JavaScript talk to Python on your computer
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # MB Execute
12
+
13
+ A safe bridge that lets JavaScript talk to Python on your computer.
14
+
15
+ ## Install
16
+
17
+ ```
18
+ pip3 install mbexe
19
+ mbexe setup
20
+ ```
@@ -0,0 +1,8 @@
1
+ mbexe/__init__.py,sha256=7R9HygN57DG2_kY8oHr-clSvgANtHn9KsIhU8Aqt8Js,60
2
+ mbexe/download.py,sha256=bnf9HCBWPIDCPRy4dWZVffpTgZ3Bkkctt2jZQSSClRo,7946
3
+ mbexe-0.1.0.dist-info/licenses/LICENSE,sha256=FAF1mAInXBVN-UchLz7MURrRmCkH8P9dLkP-f7fyRxc,1085
4
+ mbexe-0.1.0.dist-info/METADATA,sha256=Pr7wtcX_Uu_XFBpJSKm78dtPQ6l9qp4yGRHrvCvRQBE,403
5
+ mbexe-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ mbexe-0.1.0.dist-info/entry_points.txt,sha256=9Wige9CquXkTexkqR_RsQV8pAumfRc5Ub0Fw5jaYqnM,46
7
+ mbexe-0.1.0.dist-info/top_level.txt,sha256=yOXS183Ktpd99AZdJ4JcM3Y4tw9gLdXd6QO1w4Y8uWU,6
8
+ mbexe-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mbexe = mbexe.download:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mellow Blue - by Viyan Ajith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ mbexe