What's different between the batch and python is mostly:
a. SQLite queries primarily use Python's built-in sqlite3 module.
b. Output tables use the third-party tabulate module.
c. Archive extraction uses Python's zipfile.
d. Filename sanitization uses Python regular expressions.
e. There are no generated PowerShell scripts or BAT subroutines.
f. The optional missing-package check uses Python sets to
compare installed packages against Nova database packages.
g. Debugging can be enabled with DEBUG = True or the ADBFOLDER_DEBUG=1
environment variable.
As a result of the rewrite, I'm beginning to less-hate python since
it's actually more intuitive than the Windows batch scripting was. :)
Here's the new flow in the python script...
# -------------------------------------------------------------------------
# Step by step description of what this script does
# -------------------------------------------------------------------------
#
# 1. Environment & Configuration Setup
# A. Command environment
# a. Initializes Python execution environment
# b. Imports required Python modules and dependencies
# B. Configuration variables
# a. Sets default configuration paths for ADB, SQLite
# and work directories
# b. Defines the DEBUG toggle flag
# c. Defines temporary and Android backup directories
#
# 2. Dependency Verification
# A. Executable checks
# a. Locates adb.exe and checks system PATH or configured fallback path
# b. Locates sqlite3.exe and exits with an error if missing
# B. Directory setup
# a. Creates the Nova work directory if it does not exist
#
# 3. Source Selection Menu
# A. Choice [1]: Pull from Android via ADB
# a. Detects connected ADB device target
# b. Optionally launches Nova Launcher settings to create a backup
# c. Lists .novabackup files in the remote backup directory
# with fallback search of Android storage
# d. Prompts user to select or enter a backup filename/path
# e. Pulls the selected .novabackup file to the Windows workspace
# f. Renames the pulled file to backup.zip and extracts it
# into backup_extracted to retrieve nova.db
# B. Choice [2]: Use Local Database / Archive
# a. Prompts user for a custom path to nova.db, .novabackup or .zip
# with a retry loop
# b. Validates file existence
# c. Automatically extracts archives when necessary
# d. Optionally offers to restore a .novabackup database to the device
#
# 4. Database Verification & Target Enumeration
# A. Database validation
# a. Verifies that nova.db exists at the target path
# B. Section 1 [Dock]
# a. Scans dock apps [container = -101]
# b. Scans and lists any dock folders
# C. Section 2 [Panes 0-14]
# a. Iterates through home screen panes 0 to 14
# via the scan_pane function
# b. Queries pane folders [itemType = 2, container = -100]
# c. Checks for loose non-folder apps [itemType <> 2] on each pane
# D. Section 3 [Other Folders]
# a. Searches for orphaned folders not categorized under dock or panes
# b. Lists and registers remaining folders
#
# 5. User Selection & Query Execution [run_query]
# A. Selection & Sanity
# a. Prompts user to select a target number or quit [q or 0]
# b. Sanitizes the selected label to generate a safe filename
# B. Query Generation & Execution
# a. Builds a dynamic SQLite query extracting:
# - Item ID
# - Display name
# - Package name
# - Raw intent
# b. Executes the query against nova.db using Python sqlite3
# c. Falls back to the sqlite3 command-line executable if necessary
# C. Output & Formatting
# a. Writes raw tab-delimited results to output.txt
# b. Formats output columns [package_name first, display_name second]
# into an aligned table via tabulate
# c. Adds a descriptive pane/folder heading and indents the table
# by two spaces for easier reading and future concatenation
# d. Saves formatted results to [target]_apps.txt
# e. Appends each formatted export with a timestamp to
# adbfolder_log.txt without overwriting previous exports
# f. Displays the formatted results and output file locations
# D. Repeat Export
# a. Prompts user to export another folder or pane
# b. Re-enumerates targets in case the database layout has changed
# c. Repeats the selection and export process as requested
#
# 6. Optional Unplaced Third-Party Package Check [check_missing_3p]
# A. Pre-check Validation
# a. Prompts user whether to check for user-installed packages
# [-3] missing from the Nova layout
# b. Verifies ADB device connectivity and database availability
# c. Optionally prompts to resolve app titles via adb/aapt
# B. Data Collection
# a. Queries installed third-party packages from device
# [adb shell pm list packages -3]
# b. Queries all referenced packages inside nova.db
# c. Compares installed packages against packages referenced in Nova
# C. Optional App Title Resolution
# a. Runs adb shell dumpsys package for each unplaced package
# b. Searches for nonLocalizedLabel in the package information
# c. If unavailable, uses adb shell pm path to locate the APK
# d. Pulls the APK to the PC and uses aapt/aapt2 to read its label
# D. Diff Analysis & Output
# a. Identifies installed third-party packages with no Nova icon
# b. Generates a formatted package_name / app_title table
# c. Saves results to unplaced_user_apps.txt
# d. Displays package counts and the resulting unplaced app list
# E. Cleanup
# a. Removes temporary package-list files unless DEBUG=1
# b. Exits cleanly
#
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
Re: PSA/QUESTION: Porting Windows batch to Python for macOS/Linux users
- From
- Maria Sophia <mari…@comprehension.com>
- Reply-To
- pusv…@getTjewytR4so+mqe2.invalid
- Organization
- BWH Usenet Archive (https://usenet.blueworldhosting.com)
- Message-ID
- <11du…@nnrp.usenet.blueworldhosting.com>
- Date