Rename cv_engine to cv_core.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import sqlite3
|
||||
import ast
|
||||
|
||||
from cv_engine.models import Card, Set
|
||||
from cv_engine.util import EngineConfig, EngineConstants, MTGConstants
|
||||
from cv_core.models import Card, Set
|
||||
from cv_core.util import MTGConstants
|
||||
|
||||
|
||||
class CardvaultDB:
|
||||
@@ -126,7 +126,7 @@ class CardvaultDB:
|
||||
"""
|
||||
Shorthand for inserting many cards at once
|
||||
Uses a single database connection for all commits
|
||||
:param card_list: list of cv_engine.models.Card objects
|
||||
:param card_list: list of cv_core.models.Card objects
|
||||
"""
|
||||
con = sqlite3.connect(self.db_file)
|
||||
with con:
|
||||
@@ -136,7 +136,7 @@ class CardvaultDB:
|
||||
def card_insert(self, card, connection=None):
|
||||
"""
|
||||
Insert a single card into the database
|
||||
:param card: An cv_engine.models.Card object
|
||||
:param card: An cv_core.models.Card object
|
||||
:param connection: (Optional) supply a database connection to use. It will not be closed after the function
|
||||
ends
|
||||
"""
|
||||
@@ -188,7 +188,7 @@ class CardvaultDB:
|
||||
"""
|
||||
Load a single card from database
|
||||
:param card_id: multiverse_id of the card
|
||||
:return: an cv_engine.models.Card object
|
||||
:return: an cv_core.models.Card object
|
||||
"""
|
||||
cur = self.connection.cursor()
|
||||
cur.row_factory = sqlite3.Row
|
||||
@@ -222,7 +222,7 @@ class CardvaultDB:
|
||||
Search for card by their name.
|
||||
Search results are limited to 50 results.
|
||||
:param search_term: Search String
|
||||
:return: List of 'cv_engine.models.Card' objects
|
||||
:return: List of 'cv_core.models.Card' objects
|
||||
"""
|
||||
cur = self.connection.cursor()
|
||||
cur.row_factory = sqlite3.Row
|
||||
@@ -234,7 +234,7 @@ class CardvaultDB:
|
||||
def lib_get_all(self) -> list:
|
||||
"""
|
||||
Load all cards in library from database in alphabetical order
|
||||
:return: A list containing all cards in library as 'cv_engine.models.Card'
|
||||
:return: A list containing all cards in library as 'cv_core.models.Card'
|
||||
"""
|
||||
cur = self.connection.cursor()
|
||||
cur.row_factory = sqlite3.Row
|
||||
@@ -1,24 +1,24 @@
|
||||
import os
|
||||
import itertools
|
||||
|
||||
from cv_engine.database import CardvaultDB
|
||||
from cv_engine.util import EngineConfig, EngineConstants, Utilities
|
||||
from cv_core.database import CardvaultDB
|
||||
from cv_core.util import CoreConfig, CoreConstants, CoreUtilities
|
||||
|
||||
|
||||
class CardvaultEngine:
|
||||
def __init__(self, config_file=False):
|
||||
""" Create a new cv_engine instance
|
||||
""" Create a new cv_core instance
|
||||
:param config_file: File path of the configuration file
|
||||
"""
|
||||
if config_file:
|
||||
Utilities.apply_config(config_file)
|
||||
db_file_path = os.path.join(EngineConstants.config_path, EngineConfig.db_file)
|
||||
CoreUtilities.apply_config(config_file)
|
||||
db_file_path = os.path.join(CoreConstants.config_path, CoreConfig.db_file)
|
||||
self.database = CardvaultDB(db_file_path)
|
||||
|
||||
def get_card(self, card_id):
|
||||
""" Load a card object from database
|
||||
:param card_id: multiverse id of a card
|
||||
:return: an cv_engine.model.Card object
|
||||
:return: an cv_core.model.Card object
|
||||
"""
|
||||
return self.database.card_load(card_id)
|
||||
|
||||
@@ -30,7 +30,7 @@ class CardvaultEngine:
|
||||
|
||||
def get_all_categories(self) -> dict:
|
||||
""" Get all categories an the cards that are contained within them
|
||||
:return: A dict with the category names and cv_engine.models.Card objects as values
|
||||
:return: A dict with the category names and cv_core.models.Card objects as values
|
||||
"""
|
||||
categories = self.database.category_get_all()
|
||||
all_ids = set(itertools.chain.from_iterable(categories.values()))
|
||||
@@ -1,18 +1,17 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from cv_engine.models import Card
|
||||
from cv_core.models import Card
|
||||
|
||||
|
||||
class EngineConfig:
|
||||
"""
|
||||
Configuration class for the Cardvault engine
|
||||
class CoreConfig:
|
||||
""" Configuration class for the Cardvault engine
|
||||
Defines default values for all settings
|
||||
Should be changed at runtime to load customized settings
|
||||
"""
|
||||
# Should cv_engine show duplicate names in searches
|
||||
# Should cv_core show duplicate names in searches
|
||||
duplicate_names_in_search = True
|
||||
# Log level for cv_engine
|
||||
# Log level for cv_core
|
||||
log_level = 0
|
||||
# Name of the database file
|
||||
db_file = 'cardvault.db'
|
||||
@@ -22,9 +21,8 @@ class EngineConfig:
|
||||
icon_cache_path = os.path.join(os.path.expanduser('~'), '.cache', 'cardvault', 'icons')
|
||||
|
||||
|
||||
class EngineConstants:
|
||||
"""
|
||||
Constants of cv_engine
|
||||
class CoreConstants:
|
||||
""" Constants of cv_core
|
||||
Contains version number, application infos, etc.
|
||||
"""
|
||||
# Version of the cardvault engine
|
||||
@@ -36,8 +34,7 @@ class EngineConstants:
|
||||
|
||||
|
||||
class MTGConstants:
|
||||
"""
|
||||
This class contains constants that can be used within the whole program
|
||||
""" This class contains constants that can be used within the whole program
|
||||
Included are for example the the official color order or rarities
|
||||
"""
|
||||
# Color order for mana symbols
|
||||
@@ -58,10 +55,8 @@ class MTGConstants:
|
||||
}
|
||||
|
||||
|
||||
class Utilities:
|
||||
"""
|
||||
The class offers methods for general usage thorough the program.
|
||||
"""
|
||||
class CoreUtilities:
|
||||
""" The class offers methods for general usage thorough the program. """
|
||||
@staticmethod
|
||||
def apply_config(filename):
|
||||
"""
|
||||
@@ -71,12 +66,11 @@ class Utilities:
|
||||
with open(filename) as config_file:
|
||||
config = json.load(config_file)
|
||||
for setting, value in config.items():
|
||||
EngineConfig.__dict__[setting] = value
|
||||
CoreConfig.__dict__[setting] = value
|
||||
|
||||
@staticmethod
|
||||
def parse_mtgjson_cards(json_data):
|
||||
"""
|
||||
Parse a json object to
|
||||
""" Parse a json object to
|
||||
:param json_data:
|
||||
"""
|
||||
output = []
|
||||
@@ -3,7 +3,7 @@ gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
from cv_gtk3.gtk_util import GTKUtilities
|
||||
from cv_engine.util import MTGConstants
|
||||
from cv_core.util import MTGConstants
|
||||
|
||||
|
||||
class CardView(Gtk.ScrolledWindow):
|
||||
|
||||
@@ -5,7 +5,7 @@ import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
from cv_engine import engine, util
|
||||
from cv_core import engine, util
|
||||
|
||||
from cv_gtk3.main_window import MainWindowFunctions
|
||||
from cv_gtk3.setting import GUISettings
|
||||
@@ -28,14 +28,14 @@ class CardvaultGTK(MainWindowFunctions):
|
||||
"search": self.ui.get_object("searchView"),
|
||||
}
|
||||
# Verify that cache directories exist
|
||||
if not os.path.isdir(util.EngineConfig.cache_path):
|
||||
os.mkdir(util.EngineConfig.cache_path)
|
||||
if not os.path.isdir(util.EngineConfig.icon_cache_path):
|
||||
os.mkdir(util.EngineConfig.icon_cache_path)
|
||||
if not os.path.isdir(util.CoreConfig.cache_path):
|
||||
os.mkdir(util.CoreConfig.cache_path)
|
||||
if not os.path.isdir(util.CoreConfig.icon_cache_path):
|
||||
os.mkdir(util.CoreConfig.icon_cache_path)
|
||||
# Load single mana icons
|
||||
GTKUtilities.mana_icons = GTKUtilities.load_icon_cache(os.path.join(GTKUtilities.resources_path, 'mana'))
|
||||
# Load the the pre constructed icon cache
|
||||
GTKUtilities.precon_icon_cache = GTKUtilities.load_icon_cache(util.EngineConfig.icon_cache_path)
|
||||
GTKUtilities.precon_icon_cache = GTKUtilities.load_icon_cache(util.CoreConfig.icon_cache_path)
|
||||
# Call constructor of superclasses
|
||||
MainWindowFunctions.__init__(self, self.ui)
|
||||
# Create Signal handlers and connect them to the UI
|
||||
|
||||
@@ -9,7 +9,7 @@ try:
|
||||
except ImportError as err:
|
||||
print('PIL imaging library is not installed')
|
||||
|
||||
from cv_engine.util import EngineConfig
|
||||
from cv_core.util import CoreConfig
|
||||
|
||||
|
||||
class GTKUtilities:
|
||||
@@ -64,7 +64,7 @@ class GTKUtilities:
|
||||
return
|
||||
image.paste(loaded, (x_pos, 0))
|
||||
# Save pre build icon file
|
||||
path = os.path.join(EngineConfig.icon_cache_path, "_".join(glyphs) + ".png")
|
||||
path = os.path.join(CoreConfig.icon_cache_path, "_".join(glyphs) + ".png")
|
||||
image.save(path)
|
||||
try:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)
|
||||
|
||||
Reference in New Issue
Block a user