-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: solve Persistent startup not loading roles.
Roles are always calculated at startup in Clean mode, but in Persistent mode the calculation is skipped entirely, trusting the DB. The build process deleted part of the DB leading to no role reloaded. This post build script will ensure the integrity of the DB after the build process is completed
- Loading branch information
Showing
3 changed files
with
88 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# setup.py | ||
import os | ||
import pathlib | ||
import getopt, sys | ||
import shutil | ||
|
||
# Remove 1st argument from the | ||
# list of command line arguments | ||
argumentList = sys.argv[1:] | ||
|
||
# Options | ||
options = "hn:" | ||
|
||
# Long options | ||
long_options = ["help", "no_clean"] | ||
|
||
def handle_command_line_arguments() -> bool: | ||
no_cleanup: bool = False | ||
try: | ||
# Parsing argument | ||
arguments, values = getopt.getopt(argumentList, options, long_options) | ||
|
||
# checking each argument | ||
for currentArgument, _currentValue in arguments: | ||
|
||
if currentArgument in ("-h", "--help"): | ||
print("This script is used as a post build cleanup script for BYBE. \n" | ||
"Should be executed every time a Persistent build (app) needs to be mad as it ensure a correct DB is used. \n" | ||
"Pass the --no-clean or -n argument to avoid deleting files (db used for builds)") | ||
elif currentArgument in ("-n", "--no_clean"): | ||
no_cleanup = True | ||
except getopt.error: | ||
pass | ||
return no_cleanup | ||
|
||
def main(): | ||
# Check if the file already exists or needs downloading | ||
print("Executing post build script...") | ||
no_cleanup: bool = handle_command_line_arguments() is True | ||
clean_db: str = "database.db_copy" | ||
dirty_db: str = "database.db" | ||
if os.path.exists(clean_db): | ||
print("Restoring clean DB file...") | ||
pathlib.Path(dirty_db).unlink(missing_ok=True) | ||
shutil.copyfile(clean_db, dirty_db) | ||
else: | ||
print("Cannot restore clean DB, will use the dirty DB used for build...") | ||
if not no_cleanup: | ||
print("Cleaning up DB copy...") | ||
pathlib.Path(clean_db).unlink(missing_ok=True) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,60 @@ | ||
# setup.py | ||
import os | ||
import shutil | ||
import urllib.request | ||
import getopt, sys | ||
from typing import Optional | ||
from typing import Tuple | ||
|
||
# Remove 1st argument from the | ||
# list of command line arguments | ||
argumentList = sys.argv[1:] | ||
|
||
# Options | ||
options = "hd:" | ||
options = "hdc:" | ||
|
||
# Long options | ||
long_options = ["help", "db_version="] | ||
long_options = ["help", "db_version=", "copy_db"] | ||
|
||
def handle_command_line_arguments() -> Optional[str]: | ||
def handle_command_line_arguments() -> Tuple[str, bool]: | ||
db_version: str = "2.3.0" # Oldest DB version publicly available | ||
copy_db: bool = False | ||
try: | ||
# Parsing argument | ||
arguments, values = getopt.getopt(argumentList, options, long_options) | ||
|
||
# checking each argument | ||
for currentArgument, currentValue in arguments: | ||
|
||
if currentArgument in ("-h", "--help"): | ||
print("This script downloads or creates necessary file to build BYBE. \n" | ||
"Should be executed the first time the project is built in the machine or when resetting the database \n" | ||
"Pass the --db_version or -d argument to input a specific BYBE-DB version to download (>= 2.3.0)") | ||
"Pass the --db_version or -d argument to input a specific BYBE-DB version to download (>= 2.3.0) \n" | ||
"Use the --copy or -c argument to temporary copy the database (both downloaded or already present). \n" | ||
"This is used to enable Persistent startup (build with db copy and then delete the dirty db used to build)") | ||
elif currentArgument in ("-d", "--db_version"): | ||
return currentValue | ||
db_version = currentValue | ||
elif currentArgument in ("-c", "--copy_db"): | ||
copy_db = True | ||
except getopt.error: | ||
pass | ||
return db_version, copy_db | ||
|
||
def main(): | ||
# Check if the file already exists or needs downloading | ||
db_version: str = handle_command_line_arguments() | ||
print(f"Using DB version: {db_version}") or "2.3.0" # Oldest DB version publicly available | ||
x = handle_command_line_arguments() | ||
db_version: str = x[0] | ||
copy_enabled: bool = x[1] | ||
print(f"Using DB version: {db_version}") | ||
remote_url: str = f"https://github.com/RakuJa/BYBE-DB/releases/download/v{db_version}/database.db" | ||
destination_file: str = "database.db" | ||
if not os.path.exists(destination_file): | ||
database_file: str = "database.db" | ||
if not os.path.exists(database_file): | ||
print("Downloading the database file...") | ||
urllib.request.urlretrieve(remote_url, destination_file) | ||
urllib.request.urlretrieve(remote_url, database_file) | ||
else: | ||
print("Database file already exists, skipping download.") | ||
if copy_enabled: | ||
destination_file: str = f"{database_file}_copy" | ||
shutil.copyfile(database_file, destination_file) | ||
print(f"Copied db to {destination_file}") | ||
|
||
if __name__ == '__main__': | ||
main() |