Skip to content

Commit

Permalink
Merge pull request #40 from mrf345/testing
Browse files Browse the repository at this point in the history
Final refactoring prior to 0.6 release
  • Loading branch information
mrf345 authored Jan 1, 2020
2 parents 8037773 + ce0973b commit 0e39533
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Current FQM Version
VERSION = "0.5 beta"
VERSION = "0.6 beta"

SUPPORTED_LANGUAGES = {
# NOTE: The officially supported languages.
Expand Down
12 changes: 6 additions & 6 deletions app/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from gevent import monkey, pywsgi
from gevent.event import Event as thevent

from app.utils import r_path, solve_path, get_accessible_ips, get_random_available_port, is_port_available
from app.utils import absolute_path, solve_path, get_accessible_ips, get_random_available_port, is_port_available
from app.middleware import gtranslator
from app.constants import SUPPORTED_LANGUAGES, VERSION

Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self, app=None):
super(MainWindow, self).__init__()
self.app = app
global_layout = QVBoxLayout(self)
icon_path = r_path(solve_path('static/images/favicon.png'))
icon_path = absolute_path(solve_path('static/images/favicon.png'))
# NOTE: need to use objective message boxes instead of functions to set font
self.font = QFont("static/gfonts/Amiri-Regular.ttf", 12, QFont.Bold)
self.fonts = QFont("static/gfonts/Amiri-Regular.ttf", 10, QFont.Bold)
Expand Down Expand Up @@ -82,7 +82,7 @@ def initiate(self, icon):

def set_status(self, global_layout):
font = self.font
self.status_icon = QIcon(r_path(solve_path('static/images/pause.png')))
self.status_icon = QIcon(absolute_path(solve_path('static/images/pause.png')))
self.status_icon_container = QLabel('Icond', self)
self.status_icon = self.status_icon.pixmap(70, 70, QIcon.Active, QIcon.On)
self.status_icon_container.setPixmap(self.status_icon)
Expand Down Expand Up @@ -176,10 +176,10 @@ def set_start_and_stop(self, global_layout):
self.start_button = QPushButton('Start', self)
self.start_button.clicked.connect(self.start_server)
self.start_button.setFont(self.fonts)
self.start_button.setIcon(QIcon(r_path(solve_path('static/images/play.png'))))
self.start_button.setIcon(QIcon(absolute_path(solve_path('static/images/play.png'))))
self.stop_button = QPushButton('Stop', self)
self.stop_button.clicked.connect(self.stop_server)
self.stop_button.setIcon(QIcon(r_path(solve_path('static/images/pause.png'))))
self.stop_button.setIcon(QIcon(absolute_path(solve_path('static/images/pause.png'))))
self.start_button.setToolTip(self.get_translation('Start the server'))
self.stop_button.setToolTip(self.get_translation('Stop the server'))
self.stop_button.setEnabled(False)
Expand All @@ -199,7 +199,7 @@ def start_server(self):
self.stop_button.setEnabled(True)
self.select_ip.setEnabled(False)
self.select_port.setEnabled(False)
self.status_icon = QIcon(r_path(solve_path('static/images/play.png')))
self.status_icon = QIcon(absolute_path(solve_path('static/images/play.png')))
self.status_icon = self.status_icon.pixmap(70, 70, QIcon.Active, QIcon.On)
self.status_icon_container.setPixmap(self.status_icon)
current = self.select_ips_ports_change()
Expand Down
8 changes: 4 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from app.views.core import core
from app.views.customize import cust_app
from app.views.manage import manage_app
from app.utils import mse, r_path, log_error
from app.utils import mse, absolute_path, log_error
from app.database import Settings
from app.constants import SUPPORTED_LANGUAGES, SUPPORTED_MEDIA_FILES, VERSION

Expand All @@ -37,14 +37,14 @@ def create_app(config={}):
app: Flask app
app with settings and blueprints loadeds.
'''
app = Flask(__name__, static_folder=r_path('static'), template_folder=r_path('templates'))
app = Flask(__name__, static_folder=absolute_path('static'), template_folder=absolute_path('templates'))
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + r_path('data.sqlite')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + absolute_path('data.sqlite')
# Autoreload if templates change
app.config['TEMPLATES_AUTO_RELOAD'] = True
# flask_upload settings
# app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # Remove Upload limit. FIX ISSUE
app.config['UPLOADED_FILES_DEST'] = r_path('static/multimedia')
app.config['UPLOADED_FILES_DEST'] = absolute_path('static/multimedia')
app.config['UPLOADED_FILES_ALLOW'] = reduce(lambda sum, group: sum + group, SUPPORTED_MEDIA_FILES)
app.config['SECRET_KEY'] = os.urandom(24)
app.config.update(config)
Expand Down
10 changes: 5 additions & 5 deletions app/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from PIL import Image, ImageDraw, ImageFont
from os import remove, getcwd, path, name, popen, system

from app.utils import r_path, get_with_alias
from app.utils import absolute_path, get_with_alias
from app.constants import VERSION
from app.middleware import gtranslator

Expand Down Expand Up @@ -136,9 +136,9 @@ def center(text, t, f):
fs1, fs2 = fsizeit(text, t, f)
return ((text.size[0] - fs1) / 2, (text.size[1] - fs2) / 2)
if name == 'nt':
fpath = r_path('static\\gfonts\\arial.ttf')
fpath = absolute_path('static\\gfonts\\arial.ttf')
else:
fpath = r_path('static/gfonts/arial.ttf')
fpath = absolute_path('static/gfonts/arial.ttf')
fonts = [ImageFont.truetype(fpath, 50),
ImageFont.truetype(fpath, 30),
ImageFont.truetype(fpath, 25)]
Expand Down Expand Up @@ -259,9 +259,9 @@ def center(text, t, f):
return ((text.size[0] - fs1) / 2, (text.size[1] - fs2) / 2)

if name == 'nt':
fpath = r_path('static\\gfonts\\arial.ttf')
fpath = absolute_path('static\\gfonts\\arial.ttf')
else:
fpath = r_path('static/gfonts/arial.ttf')
fpath = absolute_path('static/gfonts/arial.ttf')
fonts = [ImageFont.truetype(fpath, 50),
ImageFont.truetype(fpath, 30),
ImageFont.truetype(fpath, 25)]
Expand Down
53 changes: 31 additions & 22 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
import sys
from traceback import TracebackException
from datetime import datetime
from random import randint
Expand All @@ -19,6 +18,28 @@
from app.middleware import db


def absolute_path(relative_path):
''' Get an absolute path from a relative one.
Parameters
----------
relative_path: str
relative path to make absolute.
Returns
-------
Absolute path from `relative_path`
'''
delimiter = '\\' if os.name == 'nt' else '/'
base_path = os.path.abspath('.')
clean_path = relative_path

if clean_path.startswith(delimiter):
clean_path = clean_path[len(delimiter):]

return os.path.join(base_path, clean_path)


def ids (list_of_modules):
''' Helper to retrieve list of ids from a list of modules.
Expand Down Expand Up @@ -96,7 +117,7 @@ def log_error(error):
error: Error instance
error that we want to log.
'''
log_file = r_path('errors.log')
log_file = absolute_path('errors.log')

not os.path.isfile(log_file) and os.system(f'touch {log_file}')
with open(log_file, 'a') as file:
Expand Down Expand Up @@ -175,7 +196,14 @@ def get_random_available_port(ip):


def get_with_alias():
''' to solve querying aliases without app_context in languages. '''
''' Resolve querying aliases without app_context in languages.
Returns
-------
Dict of texts with aliases embodied.
TODO: Cleanup this, there must be a better way to resolve it.
'''
class Aliases(object):
office = 'office'
ticket = 'ticket'
Expand All @@ -184,11 +212,6 @@ class Aliases(object):
alias = Aliases()
base_path = os.path.abspath('.')

try:
base_path = sys._MEIPASS
except Exception:
pass

try:
if os.path.isfile(os.path.join(base_path, 'data.sqlite')):
Base = automap_base()
Expand Down Expand Up @@ -251,20 +274,6 @@ def getFolderSize(folder, safely=False):
return int(float(total_size / 1024 / 1024))


def r_path(relative_path):
''' Get absolute path to resource, works for dev and for PyInstaller '''
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath('.')
# Fixing multimedia folder not found issue
if '/' in relative_path or '\\' in relative_path:
relative_path = ('\\' if os.name == 'nt' else '/').join(
relative_path.split('\\' if os.name == 'nt' else '/'))
return os.path.join(base_path, relative_path)


def solve_path(path):
''' fix path for window os '''
return path.replace('/', '\\') if os.name == 'nt' else path
4 changes: 2 additions & 2 deletions app/views/administrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import app.database as data
from app.middleware import db, login_manager
import app.forms as forms
from app.utils import r_path, get_module_columns, get_module_values
from app.utils import absolute_path, get_module_columns, get_module_values
from app.helpers import reject_not_god, reject_not_admin, reject_god


Expand Down Expand Up @@ -78,7 +78,7 @@ def csv():
return redirect(url_for('core.root'))

module = getattr(data, form.table.data, None)
csv_path = r_path(f'csv_{form.table.data}.csv')
csv_path = absolute_path(f'csv_{form.table.data}.csv')
delimiter = forms.export_delimiters[form.delimiter.data]

with open(csv_path, 'w+') as csv_file:
Expand Down
6 changes: 3 additions & 3 deletions app/views/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import app.database as data
from app.middleware import db, files
from app.printer import listp, get_windows_printers
from app.utils import r_path, getFolderSize
from app.utils import absolute_path, getFolderSize
from app.constants import SUPPORTED_MEDIA_FILES
from app.helpers import reject_not_admin

Expand Down Expand Up @@ -284,7 +284,7 @@ def multimedia(aa):
nofl = 300
# size folder limit in MB
sfl = 2000 # Fix limited upload folder size
dire = r_path('static/multimedia/')
dire = absolute_path('static/multimedia/')
pf = data.Media.query.order_by(data.Media.id.desc()).first()
if pf is not None:
pf = pf.name
Expand Down Expand Up @@ -407,7 +407,7 @@ def multimedia(aa):
@reject_not_admin
def multi_del(f_id):
""" to delete multimedia file """
dire = r_path('static/multimedia/')
dire = absolute_path('static/multimedia/')
if data.Media.query.filter_by(used=False).count() <= 0:
flash("Error: there is no unused multimedia file to be removed !",
'danger')
Expand Down
4 changes: 2 additions & 2 deletions gt_cached.json
Original file line number Diff line number Diff line change
Expand Up @@ -2489,14 +2489,14 @@
"it": "Seleziona un modello per touch screen:"
},
"Server is <u> Not running </u> <br>": {
"ar": "\u0627\u0644\u0640\u0640\u062e\u0640\u062f\u0645\u0629 <u>\u0645\u062a\u0640\u0640\u0648\u0642\u0641\u0640\u0640\u0629</u><br>",
"ar": "\u0627\u0644\u062e\u062f\u0645\u0647 \u0644\u064a\u0633\u062a \u0645\u0641\u0639\u0644\u0647 \u0628\u0639\u062f<br>",
"en": "Server is <u> Not running </u> <br>",
"es": "el servidor <u>no se est\u00e1 ejecutando</u> <br>",
"fr": "Tout le cr\u00e9dit r\u00e9serv\u00e9 \u00e0 l'auteur de la version FQM ",
"it": "il server <u> non \u00e8 in esecuzione </u> <br>"
},
"Server is <u>Running</u> <br> On : ": {
"ar": "\u0627\u0644\u062e\u062f\u0645\u0629 <u>\u0645\u0634\u063a\u0640\u0640\u0644\u0629</u> \u0648 \u062a\u0628\u062b \u0639\u0644\u0649 : <br>",
"ar": "\u0627\u0644\u062e\u062f\u0645\u0647 \u0645\u0641\u0639\u0644\u0647 \u0648 \u062a\u0628\u062b \u0645\u0646 \u062e\u0644\u0627\u0644 : <br>",
"en": "Server is <u>Running</u> <br> On : ",
"es": "el servidor <u>se est\u00e1 ejecutando</u> : <br> ",
"fr": "le serveur <u> fonctionne </u> <br> sur : ",
Expand Down
2 changes: 1 addition & 1 deletion installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# printing group. this script purpose is to ease the process of installing, uninstalling
# FQM on Linux and MacOS.

version="0.5"
version="0.6"
pip_exi=`command -v pip`
python=`command -v python`
virtenv=`command -v virtualenv`
Expand Down
11 changes: 8 additions & 3 deletions run.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ block_cipher = None


a = Analysis(['run.py'],
pathex=['C:\\Documents and Settings\\testor\\Desktop\\FQM'],
pathex=['C:\\Users\\tester\\Desktop\\fqm'],
binaries=[],
datas=[('arabic_reshaper\*', 'arabic_reshaper')],
hiddenimports=["'email.mime.multipart'", "'win32com.client'", "'pythoncom'", "'email.mime.message'", "'email.mime.text'", "'email.mime.image'", "'email.mime.audio'", "'sqlalchemy.sql.default_comparator'", "'jinja2'"],
hiddenimports=[
'email.mime.multipart', 'win32com.client', 'pythoncom', 'email.mime.message',
'email.mime.text', 'email.mime.image', 'email.mime.audio',
'sqlalchemy.sql.default_comparator', 'jinja2'
],
hookspath=[],
runtime_hooks=[],
excludes=[],
Expand All @@ -25,4 +29,5 @@ exe = EXE(pyz,
debug=False,
strip=False,
upx=True,
console=False , icon='favicon.ico')
console=False ,
icon='C:\\Users\\tester\\Desktop\\fqm\\static\\images\\favicon.ico')
4 changes: 2 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from app.main import create_db, bundle_app
from app.middleware import db
from app.database import User, Operators, Office, Task
from app.utils import r_path
from app.utils import absolute_path


NAMES = ('Aaron Enlightened', 'Abbott Father', 'Abel Breath', 'Abner Father',
Expand All @@ -28,7 +28,7 @@
PREFIXES = list(map(lambda i: chr(i).upper(), range(97,123)))

MODULES = [User, Operators, Task, Office]
DB_PATH = r_path('testing.sqlite')
DB_PATH = absolute_path('testing.sqlite')


@pytest.fixture
Expand Down

0 comments on commit 0e39533

Please sign in to comment.