Skip to content

Commit

Permalink
separate user content to make them persistent between upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
eliranwong committed Oct 26, 2024
1 parent e964bc9 commit 1ff5533
Show file tree
Hide file tree
Showing 38 changed files with 223 additions and 178 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/
setup(
name=package,
version="0.1.15",
version="0.1.18",
python_requires=">=3.8, <3.13",
description=f"UniqueBible App is a cross-platform & offline bible application, integrated with high-quality resources and unique features. Developers: Eliran Wong and Oliver Tseng",
long_description=long_description,
Expand Down
64 changes: 64 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os, requests, pkg_resources
from shutil import copytree
from pathlib import Path
from packaging import version


# go to resource directory
thisFile = os.path.realpath(__file__)
wd = os.path.dirname(thisFile)
if os.getcwd() != wd:
os.chdir(wd)

ubahome = os.path.expanduser(os.path.join("~", "UniqueBible"))

if not os.path.isdir(ubahome):
Path(ubahome).mkdir(parents=True, exist_ok=True)
for i in ("audio", "htmlResources", "import", "macros", "marvelData", "music", "notes", "temp", "terminal_history", "terminal_mode", "thirdParty", "video", "webstorage", "workspace"):
targetFolder = os.path.join(ubahome, i)
if not os.path.isdir(targetFolder):
copytree(i, targetFolder, dirs_exist_ok=True)
#copytree(i, os.path.join(ubahome, i), dirs_exist_ok=True)

# Add folders below for all new folders created after version 0.1.17
# ...

# change directory
if os.getcwd() != ubahome:
os.chdir(ubahome)

# user plugins; create folders for users to place their own plugins
# TODO: user plugins not working for now; will implement later
for i in ("chatGPT", "config", "context", "event", "language", "layout", "menu", "shutdown", "startup", "terminal", "text_editor"):
Path(os.path.join(ubahome, "plugins", i)).mkdir(parents=True, exist_ok=True)


def getPackageInstalledVersion(package):
try:
installed_version = pkg_resources.get_distribution(package).version
return version.parse(installed_version)
except pkg_resources.DistributionNotFound:
return None

def getPackageLatestVersion(package):
try:
response = requests.get(f"https://pypi.org/pypi/{package}/json", timeout=10)
latest_version = response.json()['info']['version']
return version.parse(latest_version)
except:
return None

thisPackage = "uniquebible"

installed_version = getPackageInstalledVersion(thisPackage)
if installed_version is None:
print("Installed version information is not accessible!")
else:
print(f"Installed version: {installed_version}")
latest_version = getPackageLatestVersion(thisPackage)
if latest_version is None:
print("Latest version information is not accessible at the moment!")
elif installed_version is not None:
print(f"Latest version: {latest_version}")
if latest_version > installed_version:
print("Run `pip install --upgrade uniquebible` to upgrade!")
64 changes: 64 additions & 0 deletions uniquebible/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os, requests, pkg_resources
from shutil import copytree
from pathlib import Path
from packaging import version


# go to resource directory
thisFile = os.path.realpath(__file__)
wd = os.path.dirname(thisFile)
if os.getcwd() != wd:
os.chdir(wd)

ubahome = os.path.expanduser(os.path.join("~", "UniqueBible"))

if not os.path.isdir(ubahome):
Path(ubahome).mkdir(parents=True, exist_ok=True)
for i in ("audio", "htmlResources", "import", "macros", "marvelData", "music", "notes", "temp", "terminal_history", "terminal_mode", "thirdParty", "video", "webstorage", "workspace"):
targetFolder = os.path.join(ubahome, i)
if not os.path.isdir(targetFolder):
copytree(i, targetFolder, dirs_exist_ok=True)
#copytree(i, os.path.join(ubahome, i), dirs_exist_ok=True)

# Add folders below for all new folders created after version 0.1.17
# ...

# change directory
if os.getcwd() != ubahome:
os.chdir(ubahome)

# user plugins; create folders for users to place their own plugins
# TODO: user plugins not working for now; will implement later
for i in ("chatGPT", "config", "context", "event", "language", "layout", "menu", "shutdown", "startup", "terminal", "text_editor"):
Path(os.path.join(ubahome, "plugins", i)).mkdir(parents=True, exist_ok=True)


def getPackageInstalledVersion(package):
try:
installed_version = pkg_resources.get_distribution(package).version
return version.parse(installed_version)
except pkg_resources.DistributionNotFound:
return None

def getPackageLatestVersion(package):
try:
response = requests.get(f"https://pypi.org/pypi/{package}/json", timeout=10)
latest_version = response.json()['info']['version']
return version.parse(latest_version)
except:
return None

thisPackage = "uniquebible"

installed_version = getPackageInstalledVersion(thisPackage)
if installed_version is None:
print("Installed version information is not accessible!")
else:
print(f"Installed version: {installed_version}")
latest_version = getPackageLatestVersion(thisPackage)
if latest_version is None:
print("Latest version information is not accessible at the moment!")
elif installed_version is not None:
print(f"Latest version: {latest_version}")
if latest_version > installed_version:
print("Run `pip install --upgrade uniquebible` to upgrade!")
5 changes: 2 additions & 3 deletions uniquebible/gui/AlephMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ def create_menu(self):
menu1.addAction(
QAction(config.thisTranslation["menu_startup_macro"], self, triggered=self.setStartupMacro))

menu1.addAction(
QAction(config.thisTranslation["menu1_update"], self, triggered=self.showUpdateAppWindow))
#menu1.addAction(QAction(config.thisTranslation["menu1_update"], self, triggered=self.showUpdateAppWindow))

menu1.addAction(
QAction(config.thisTranslation["menu_quit"], self, shortcut=sc.quitApp, triggered=self.quitApp))
Expand Down Expand Up @@ -500,7 +499,7 @@ def create_menu(self):
# plugins
if config.enablePlugins:
menu = addMenu(self.menuBar(), "menu_plugins")
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join("plugins", "menu"), "py"):
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join(config.packageDir, "plugins", "menu"), "py"):
if not plugin in config.excludeMenuPlugins:
if "_" in plugin:
feature, shortcut = plugin.split("_", 1)
Expand Down
1 change: 1 addition & 0 deletions uniquebible/gui/AppUpdateDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(self, parent):
self.updateNowButton.setFocus()

def updateNow(self):
return None # remove old way of update
debug = False
self.updateNowButton.setText(config.thisTranslation["Updating"])
self.updateNowButton.setEnabled(False)
Expand Down
6 changes: 3 additions & 3 deletions uniquebible/gui/ClassicMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def create_menu(self):
for feature, action, shortcut in items:
addMenuItem(subMenu, feature, self, action, shortcut)
menu.addSeparator()
addMenuItem(menu, "menu1_update", self, self.showUpdateAppWindow, None)
menu.addSeparator()
#addMenuItem(menu, "menu1_update", self, self.showUpdateAppWindow, None)
#menu.addSeparator()

appIcon = QIcon(os.path.join("htmlResources", "UniqueBibleApp.png"))
quit_action = QAction(appIcon, config.thisTranslation["menu1_exit"], self, shortcut=sc.quitApp, triggered=self.quitApp)
Expand Down Expand Up @@ -492,7 +492,7 @@ def create_menu(self):
# plugins
if config.enablePlugins:
menu = addMenu(self.menuBar(), "menu_plugins")
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join("plugins", "menu"), "py"):
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join(config.packageDir, "plugins", "menu"), "py"):
if not plugin in config.excludeMenuPlugins:
if "_" in plugin:
feature, shortcut = plugin.split("_", 1)
Expand Down
8 changes: 4 additions & 4 deletions uniquebible/gui/EnableIndividualPlugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setupUI(self):
dataView1.setEditTriggers(QAbstractItemView.NoEditTriggers)
dataViewModel1 = QStandardItemModel(dataView1)
dataView1.setModel(dataViewModel1)
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join("plugins", "startup"), "py"):
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join(config.packageDir, "plugins", "startup"), "py"):
item = QStandardItem(plugin)
item.setToolTip(plugin)
item.setCheckable(True)
Expand All @@ -68,7 +68,7 @@ def setupUI(self):
dataView2.setEditTriggers(QAbstractItemView.NoEditTriggers)
dataViewModel2 = QStandardItemModel(dataView2)
dataView2.setModel(dataViewModel2)
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join("plugins", "menu"), "py"):
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join(config.packageDir, "plugins", "menu"), "py"):
item = QStandardItem(plugin)
item.setToolTip(plugin)
item.setCheckable(True)
Expand All @@ -84,7 +84,7 @@ def setupUI(self):
dataView3.setEditTriggers(QAbstractItemView.NoEditTriggers)
dataViewModel3 = QStandardItemModel(dataView3)
dataView3.setModel(dataViewModel3)
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join("plugins", "context"), "py"):
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join(config.packageDir, "plugins", "context"), "py"):
item = QStandardItem(plugin)
item.setToolTip(plugin)
item.setCheckable(True)
Expand All @@ -100,7 +100,7 @@ def setupUI(self):
dataView4.setEditTriggers(QAbstractItemView.NoEditTriggers)
dataViewModel4 = QStandardItemModel(dataView4)
dataView4.setModel(dataViewModel4)
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join("plugins", "shutdown"), "py"):
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join(config.packageDir, "plugins", "shutdown"), "py"):
item = QStandardItem(plugin)
item.setToolTip(plugin)
item.setCheckable(True)
Expand Down
6 changes: 3 additions & 3 deletions uniquebible/gui/FocusMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ def create_menu(self):
)
for feature, action in items:
addMenuItem(subMenu, feature, self, action)
menu.addSeparator()
addMenuItem(menu, "menu1_update", self, self.showUpdateAppWindow)
#menu.addSeparator()
#addMenuItem(menu, "menu1_update", self, self.showUpdateAppWindow)
menu.addSeparator()
if hasattr(config, "cli"):
addMenuItem(menu, "restart", self, self.restartApp)
Expand Down Expand Up @@ -426,7 +426,7 @@ def create_menu(self):
# plugins
if config.enablePlugins:
menu = addMenu(menuBar, "menu_plugins")
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join("plugins", "menu"), "py"):
for plugin in FileUtil.fileNamesWithoutExtension(os.path.join(config.packageDir, "plugins", "menu"), "py"):
if not plugin in config.excludeMenuPlugins:
if "_" in plugin:
feature, shortcut = plugin.split("_", 1)
Expand Down
29 changes: 5 additions & 24 deletions uniquebible/gui/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __init__(self):
self.directoryLabel.setFrameStyle(frameStyle)

# setup UI
self.setWindowTitle("UniqueBible.app [version {0:.2f}]".format(config.version))
self.setWindowTitle("UniqueBible.app")
appIcon = QIcon(config.desktopUBAIcon)
QGuiApplication.setWindowIcon(appIcon)
# setup user menu & toolbars
Expand Down Expand Up @@ -217,7 +217,7 @@ def __init__(self):
self.resizeCentral()

# check if newer version is available
self.checkApplicationUpdate()
#self.checkApplicationUpdate()
# check if newer versions of formatted bibles are available
self.checkModulesUpdate()
# Control Panel
Expand Down Expand Up @@ -608,7 +608,7 @@ def setupMenuLayout(self, layout):
windowName = layout.capitalize() + "MainWindow"
windowClass = getattr(sys.modules[__name__], windowName)
elif config.enablePlugins:
file = os.path.join(os.getcwd(), "plugins", "layout", layout+".py")
file = os.path.join(config.packageDir, "plugins", "layout", layout+".py")
if os.path.exists(file):
mod = __import__('plugins.layout.{0}'.format(layout), fromlist=[layout])
windowClass = getattr(mod, layout)
Expand Down Expand Up @@ -817,25 +817,6 @@ def restartApp(self):
config.restartUBA = True
QGuiApplication.instance().quit()

# check migration
def checkMigration(self):
return None
if config.version >= 0.56 and not config.databaseConvertedOnStartup:
try:
biblesSqlite = BiblesSqlite()
biblesWithBothVersions = biblesSqlite.migratePlainFormattedBibles()
if biblesWithBothVersions:
self.displayMessage("{0} {1}".format(config.thisTranslation["message_migration"],
config.thisTranslation["message_willBeNoticed"]))
biblesSqlite.proceedMigration(biblesWithBothVersions)
self.displayMessage(config.thisTranslation["message_done"])
if config.migrateDatabaseBibleNameToDetailsTable:
biblesSqlite.migrateDatabaseContent()
del biblesSqlite
config.databaseConvertedOnStartup = True
except:
pass

def displayMessage(self, message="", title="UniqueBible"):
if hasattr(config, "cli") and config.cli:
print(message)
Expand Down Expand Up @@ -5391,7 +5372,7 @@ def addMenuPluginButton(self, plugin, feature, icon, toolbar, translation=True):
self.addMaterialIconButton(feature, icon, partial(self.runPlugin, plugin), toolbar, translation=translation)

def isMenuPlugin(self, plugin):
return os.path.isfile(os.path.join("plugins", "menu", "{0}.py".format(plugin)))
return os.path.isfile(os.path.join(config.packageDir, "plugins", "menu", "{0}.py".format(plugin)))

def runPlugin(self, fileName, _=None):
self.crossPlatform.runPlugin(fileName)
Expand Down Expand Up @@ -5768,7 +5749,7 @@ def runBibleChatPlugins(self):
config.chatGPTApiFunctionSignatures = []
config.chatGPTApiAvailableFunctions = {}

pluginFolder = os.path.join(os.getcwd(), "plugins", "chatGPT")
pluginFolder = os.path.join(config.packageDir, "plugins", "chatGPT")
# always run 'integrate google searches'
internetSeraches = "integrate google searches"
script = os.path.join(pluginFolder, "{0}.py".format(internetSeraches))
Expand Down
Loading

0 comments on commit 1ff5533

Please sign in to comment.