def getSyncPath(lock=False): if config.account_nr is None or config.account_nr == 0: fn = config.sync_cache else: fn = config.sync_cache + str(config.account_nr) if lock: fn = fn + "_lock" return util.getDirectory(fn, share=True)
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import shelve from pathlib import Path from PyQt5.QtCore import QSemaphore from plus import config, util register_semaphore = QSemaphore(1) uuid_cache_path = util.getDirectory(config.uuid_cache) # register the path for the given uuid, assuming it points to the .alog profile containing that uuid def addPath(uuid,path): try: config.logger.debug("register:setPath(" + str(uuid) + "," + str(path) + ")") register_semaphore.acquire(1) with shelve.open(uuid_cache_path) as db: db[uuid] = path except Exception as e: config.logger.error("roast: Exception in addPath() %s",e) finally: if register_semaphore.available() < 1: register_semaphore.release(1)
# the account nr locally assocated to the current account, or None account_nr = None # the sync register that associates UUIDs with last known modification dates modified_at for profiles uploaded/synced automatially sync_cache = "sync" # the outbox queues the outgoing PUSH/PUT data requests outbox_cache = "outbox" # the log_file logs communication and other important events log_file = "artisan_plus" # Logging log_file_path = util.getDirectory(log_file,".log") logger = logging.getLogger("plus") logger.setLevel(logging.DEBUG) handler = RotatingFileHandler(log_file_path, maxBytes=200000, backupCount=1) handler.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') # - %(name)s handler.setFormatter(formatter) logger.addHandler(handler) ## Usage: ## config.logger.info("something") ## config.logger.debug('%s iteration, item=%s', i, item)
def getSyncPath(): if config.account_nr is None or config.account_nr == 0: return util.getDirectory(config.sync_cache) else: return util.getDirectory(config.sync_cache + str(config.account_nr))
# along with this program. If not, see <http://www.gnu.org/licenses/>. import json import time from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import QSemaphore, QTimer from artisanlib.util import d as decode, encodeLocal from plus import config, connection, util, controller stock_semaphore = QSemaphore( 1) # protects access to the stock_cache file and the stock dict stock_cache_path = util.getDirectory(config.stock_cache) stock = None # holds the dict with the current stock data (coffees, blends,..) ################### # stock cache update # # updates the stock cache def update(): QTimer.singleShot(2, lambda: update_blocking()) def update_blocking():
import portalocker from PyQt5.QtCore import QSemaphore from plus import config, util #### Account Cache # holding all account ids associated to a (local) running number # shared cache between the Artisan and the ArtisanViewer app account_cache_semaphore = QSemaphore(1) # shared resource between the Artisan and ArtisanViewer app protected by a file lock account_cache_path = util.getDirectory(config.account_cache,share=True) account_cache_lock_path = util.getDirectory(config.account_cache + "_lock",share=True) # register the given account_id and assign it a fresh number if not yet registered # returns the number associated to account_id or None on error def setAccount(account_id): try: config.logger.debug("account:setAccount(" + str(account_id) + ")") account_cache_semaphore.acquire(1) with portalocker.Lock(account_cache_lock_path, timeout=1) as _: with shelve.open(account_cache_path) as db: if account_id in db: return db[account_id] else: new_nr = len(db) db[account_id] = new_nr
# the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import shelve import portalocker from pathlib import Path from PyQt5.QtCore import QSemaphore from plus import config, util register_semaphore = QSemaphore(1) uuid_cache_path = util.getDirectory(config.uuid_cache, share=True) # register the path for the given uuid, assuming it points to the .alog profile containing that uuid def addPath(uuid, path): try: config.logger.debug("register:setPath(" + str(uuid) + "," + str(path) + ")") register_semaphore.acquire(1) with portalocker.Lock(uuid_cache_path, timeout=1) as _: with shelve.open(uuid_cache_path) as db: db[uuid] = str(path) except Exception as e: config.logger.error("roast: Exception in addPath() %s", e) finally: if register_semaphore.available() < 1:
# the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import persistqueue import threading import time from requests.exceptions import ConnectionError from PyQt5.QtCore import QCoreApplication from PyQt5.QtWidgets import QApplication from plus import config, util, roast, connection, sync, controller queue_path = util.getDirectory(config.outbox_cache, share=True) app = QCoreApplication.instance() queue = persistqueue.SQLiteQueue(queue_path, multithreading=True, auto_commit=False) # auto_commit=False : we keep items in the queue if not explicit marked as task_done # queue entries are dictionaries with entries # url : the URL to send the request to # data : the data dictionary that will be send in the body as JSON # verb : the HTTP verb to be used (POST or PUT) worker_thread = None
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import shelve from PyQt5.QtCore import QSemaphore from plus import config, util #### Account Cache # holding all account ids associated to a (local) running number account_cache_semaphore = QSemaphore(1) account_cache_path = util.getDirectory(config.account_cache) # register the given account_id and assign it a fresh number if not yet registered # returns the number associated to account_id or None on error def setAccount(account_id): try: config.logger.debug("account:setAccount(" + str(account_id) + ")") account_cache_semaphore.acquire(1) with shelve.open(account_cache_path) as db: if account_id in db: return db[account_id] else: new_nr = len(db) db[account_id] = new_nr return new_nr
# along with this program. If not, see <http://www.gnu.org/licenses/>. import sys import os import shelve import dbm import portalocker from pathlib import Path from PyQt5.QtCore import QSemaphore from plus import config, util register_semaphore = QSemaphore(1) uuid_cache_path = util.getDirectory(config.uuid_cache, share=True) uuid_cache_path_lock = util.getDirectory(config.uuid_cache + "_lock", share=True) def addPathShelve(uuid, path, fh): config.logger.debug("register: addPathShelve(%s,%s,_fh_)", uuid, path) try: with shelve.open(uuid_cache_path) as db: db[uuid] = str(path) config.logger.debug("register: DB type: %s", str(dbm.whichdb(uuid_cache_path))) except Exception as e: _, _, exc_tb = sys.exc_info() config.logger.error( "register: Exception in addPathShelve(%s,%s) line: %s shelve.open (1) %s",
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from persistqueue import Queue import threading import time from PyQt5.QtWidgets import QApplication from plus import config, util, roast, connection, sync, controller queue_path = util.getDirectory(config.outbox_cache) queue = Queue(queue_path) # queue entries are dictionaries with entries # url : the URL to send the request to # data : the data dictionary that will be send in the body as JSON # verb : the HTTP verb to be used (POST or PUT) worker_thread = None class Concur(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.daemon = True # OK for main to exit even if instance is still running
def getSyncPath(lock=False): fn = getSyncName() if lock: fn = fn + "_lock" return util.getDirectory(fn, share=True)