Skip to content

Added mongo export utility #138

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

simbamangu
Copy link
Contributor

Added python utility for exporting entire mongodb database as JSON from inside Scout container - for backup or analytical needs.

Changes

  • Added scout_export.py to Util folder

@vkirkl vkirkl self-requested a review March 18, 2025 17:20

### Requirements

Python 3 - tested on python 3.12, probably works down to 3.8.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should favor newer versions (3.8 is beyond e.o.l. and I plan to bump the Ubuntu versions for scout and scoutbot) ... but the dependency is here is like more on the Tcl/Tk version: my python 3.10.8 test used Tcl/Tk 8.5.9 which did not crash, but the controls were not rendered so the util was unusable (and there was not message as to why). Controls appear and most work (see below) with my python 3.11 and 3.12 tests with Tcl/Tk 9.0.1


### Installation

Install requirements ('docker' the only module needed)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be done in a virtual environment.

self.db_tree.delete(item)

try:
# Try multiple methods to find MongoDB databases
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly unnecessary - current versions of mongo will all have mongosh. Simplify?

messagebox.showwarning("Warning", "Please select an export directory first")
return

# Start export in a separate thread
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reconsider threading?
My tests with python 3.11 and 3.12, Tcl/Tk 9.0.1, MacOS 15.4 (Intel) all failed when starting the export (container, db, and export location chosen) due to threading issue.
'NSWindow should only be instantiated on the main thread!'

Example:

2025-04-25 10:06:19.354 python[73350:1034079] +[IMKInputSession subclass]: chose IMKInputSession_Modern
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow should only be instantiated on the main thread!'
*** First throw call stack:
(
	0   CoreFoundation                  	0x00007ff8055ca326 __exceptionPreprocess + 242
	1   libobjc.A.dylib                 	0x00007ff8050afbd0 objc_exception_throw + 62
	2   CoreFoundation                  	0x00007ff8055ed2b4 -[NSException raise] + 9
	3   AppKit                          	0x00007ff808ecf126 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1653
	4   AppKit                          	0x00007ff80905a811 -[NSPanel _initContent:styleMask:backing:defer:contentView:] + 50
	5   AppKit                          	0x00007ff808eceaa9 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
	6   AppKit                          	0x00007ff80905a7ca -[NSPanel initWithContentRect:styleMask:backing:defer:] + 59
	7   AppKit                          	0x00007ff808ecd2fb -[NSWindowTemplate nibInstantiate] + 341
	8   AppKit                          	0x00007ff808e99e5c -[NSIBObjectData instantiateObject:] + 223
	9   AppKit                          	0x00007ff808e995c3 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 472
	10  AppKit                          	0x00007ff808e8df84 loadNib + 413
	11  AppKit                          	0x00007ff808e8d36f +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 763
	12  AppKit                          	0x00007ff808e8cf7f -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 201
	13  AppKit                          	0x00007ff8091c4fed -[NSAlert init] + 101
	14  libtcl9tk9.0.dylib              	0x00000001019f391f Tk_MessageBoxObjCmd + 62
	15  libtcl9.0.dylib                 	0x0000000101ac4983 TclNRRunCallbacks + 73
	16  _tkinter.cpython-312-darwin.so  	0x00000001010241f0 Tkapp_Call + 560
	17  libpython3.12.dylib             	0x000000010137432a cfunction_call + 138
	18  libpython3.12.dylib             	0x0000000101326fed _PyObject_Call + 141
	19  libpython3.12.dylib             	0x000000010143a201 _PyEval_EvalFrameDefault + 52209
	20  libpython3.12.dylib             	0x0000000101329807 method_vectorcall + 343
	21  libpython3.12.dylib             	0x000000010143a201 _PyEval_EvalFrameDefault + 52209
	22  libpython3.12.dylib             	0x0000000101329807 method_vectorcall + 343
	23  libpython3.12.dylib             	0x0000000101508b1e thread_run + 78
	24  libpython3.12.dylib             	0x00000001014a7099 pythread_wrapper + 25
	25  libsystem_pthread.dylib         	0x00007ff805473253 _pthread_start + 99
	26  libsystem_pthread.dylib         	0x00007ff80546ebef thread_start + 15
)
libc++abi: terminating due to uncaught exception of type NSException
[1]	73350 abort  	python scout_export.py```


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants