Skip to content

Commit

Permalink
Windows Bugfix Update
Browse files Browse the repository at this point in the history
Caught compiler related exceptions.
Fixed bugs on Windows GUI
Cosmetic changes to Windows GUI
New Windows Binary
Updated to version 1.1.0a1
Tidied up backend + documentation
Fixed bug related to opening program on windows with no console (and thus removed console)
  • Loading branch information
2Cas committed Apr 24, 2018
1 parent 1713d94 commit ea10828
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ avr-gcc/
*.tar.gz
*.zip
q2k/BUILD EXEC.lnk
bin/*/q2k_out
*.7z
Binary file modified bin/Win/q2k_util.exe
Binary file not shown.
101 changes: 64 additions & 37 deletions q2k/core.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import argparse
import copy
import errno
import glob
import os
import pathlib
import platform
import errno
import os
import yaml
import sys
import re
import copy
import subprocess
import sys
import traceback
import yaml
import tempfile
import pyparsing as pp
import termcolor as tc
import enum as en
Expand All @@ -22,19 +24,31 @@
class defaults:

if getattr(sys, 'frozen', False):
src = os.getcwd() # If Frozen - $Q2K = [cwd]
frozen = True
src = '' #os.getcwd() # If Frozen - $Q2K = [cwd]
else: # If Live, use bundle_dir
frozen = False
src = os.path.dirname(os.path.abspath(__file__)) # else $Q2K is its own install dir, seperate from working directory

version = q2kversion
# Directories
# Directories
libs = os.path.join(src, 'lib') # Local Libs Default is $Q2K/libs/
cache = os.path.join(src, '.cache','cache_kb.yaml') # Cache Default is $Q2K/.cache/cache_kb.yaml

if frozen:
qmk = os.path.join(src, 'qmk_firmware') # QMK Directory - To be provided by user Default is $Q2K/qmk_firmware/
keyp = os.path.join(src, 'q2k_out','keyplus') # Output. This is a relative directory (default) Default is $Q2K/q2k_out/keyplus/ (Frozen)
kbf = os.path.join(src, 'q2k_out','kbfirmware')
else:
qmk = os.path.join(os.getcwd(), 'qmk_firmware') # QMK Directory - To be provided by user Default is $Q2K/qmk_firmware/
keyp = os.path.join(os.getcwd(),'q2k_out','keyplus') # Output. This is a relative directory. Default is [cwd]/q2k_out/keyplus/ (Live)
kbf = os.path.join(os.getcwd(),'q2k_out','kbfirmware')

if platform.system() == 'Linux': # AVR-GCC Compiler.
avr_gcc = 'avr-gcc' # avr-gcc for linux Default is avr-gcc (Linux)
elif platform.system() == 'Windows':
avr_gcc = os.path.join(src, 'avr-gcc', 'bin', 'avr-gcc.exe') # avr-gcc.exe for Windows Default is $Q2K/avr-gcc/bin/avr-gcc.exe (Windows)

libs = os.path.join(src, 'lib') # Local Libs - We want these to be in a single, FIXED directory. [Avoid using relative directories] Default is $Q2K/libs
cache = os.path.join(src, '.cache','cache_kb.yaml') # Cache - We want this to be in a single, FIXED directory. [Avoid using relative directories] Default is $Q2K/.cache/cache_kb.yaml
qmk = os.path.join(src, 'qmk') # QMK Directory - To be provided by user Default is [cwd]/qmk
keyp = os.path.join(os.getcwd(),'q2k_out','keyplus') # Output. This can either be fixed in one location (defined by user) or be a relative directory (default) Default is [cwd]/q2k_out/keyplus
kbf = os.path.join(os.getcwd(),'q2k_out','kbfirmware')
# Lists
qmk_nonstd_dir = ['handwired', 'converter',
'clueboard', 'lfkeyboards'] # Currently only lfkeyboards causes any issues, however it is good to be verbose here
Expand All @@ -44,6 +58,11 @@ class defaults:
# Misc
invalid_kc = 'trns' # What to set invalid KC codes to

if platform.system() == 'Linux':
print_lines = '─────────────────────────────────────────────────────────────────'
elif platform.system() == 'Windows':
print_lines = '──────────────────────────────────────────────────────────────'

# ===========================================================================================
# Console Output
# ===========================================================================================
Expand Down Expand Up @@ -279,12 +298,7 @@ def __preproc(self, kblibs, arg_list, DEBUG=False):
# Setting up -I and custom define options
qdir = os.path.join(self.__dirs['QMK dir'], 'keyboards')
kb = self.__kb.name
if platform.system() == 'Linux':
cc = ['avr-gcc', '-E']
elif platform.system() == 'Windows':
avr_gcc = os.path.join(defaults.src, 'avr-gcc', 'bin', 'avr-gcc.exe')
cc = [avr_gcc, '-E']

cc = [defaults.avr_gcc, '-E']
kbdefine = 'KEYBOARD_'+'_'.join(kblibs)
QMK_KEYBOARD_H = 'QMK_KEYBOARD_H=\"'+kb+'.h\"'
libs = ['-D', kbdefine, '-D', QMK_KEYBOARD_H, '-I'+self.__dirs['Local libs']]
Expand All @@ -297,17 +311,34 @@ def __preproc(self, kblibs, arg_list, DEBUG=False):
if DEBUG: print(' '.join(argv))

try:
output = subprocess.check_output(argv)
#app_stdout = sys.stdout
#app_stderr = sys.stderr
#sys.stdout = sys.__stdout__
#sys.stderr = sys.__stderr__

#sys.stdout = app_stdout
#sys.stderr = app_stderr

si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW

output = subprocess.check_output(argv, stdin=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=si)

return output
except subprocess.CalledProcessError as e:
err_num = e.returncode
if err_num == 1:
print(err_num)
if err_num == errno.EPERM:
self.__console.warning(['Compiler failed to read '+argv[-1]])
output = e.output
return output
else:
self.console.warning(['Potentially catastrophic segfault related compilation error'])
print(traceback.format_exc(), file=sys.stderr)
return
except OSError as e:
if e.errno == errno.ENOEXEC:
self.__console.error(['Could not find avr-gcc compiler', 'Check if avr-gcc is installed in',defaults.avr_gcc])
else:
print(traceback.format_exc(), file=sys.stderr)

def preproc_header(self, path):

Expand Down Expand Up @@ -375,7 +406,7 @@ def get_rev_info(self, rev):
return r
if r.name == 'n/a':
return r
#───────────────────────────────────────────────────────────────────────────────────────────
# ===========================================================================================
# KB and revision Information
# ===========================================================================================
class rev_info:
Expand Down Expand Up @@ -668,7 +699,7 @@ def __find(self):
try:
with open(self.__loc, 'r') as f:
self.kbo_list = yaml.load(f)
self.__console.note(['Using cached list from '+self.__loc, '--cache to reset'])
self.__console.note(['Using cached list from '+self.__loc, '--cache to reset', defaults.print_lines])
except:
self.__console.warning(['Failed to load from '+self.__loc, 'Generating new cache_kb.yaml...'])
self.__write()
Expand Down Expand Up @@ -753,9 +784,9 @@ def __write(self):
if self.kbo_list:
# Dump cache info to text file for faster processing in future
self.__save_cache()
self.__console.note(['New cache_kb.yaml successfully generated', 'Location: '+self.__loc])
self.__console.note(['New cache_kb.yaml successfully generated', 'Location: '+self.__loc, defaults.print_lines])
else:
self.__console.warning(['No keyboard information found', 'Check QMK directory location in pref.yaml : '+self.__qmk])
self.__console.warning(['No keyboard information found', 'Check QMK directory location in pref.yaml : '+self.__qmk, defaults.print_lines])


def __find_layout_names(self, kbo):
Expand Down Expand Up @@ -806,15 +837,12 @@ def __find_layout_names(self, kbo):

def __save_cache(self):
path = os.path.split(self.__loc)[0]
print(self.__loc)
print(path)
#======================================================================================================================
if not os.path.exists(path):
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST and os.path.isdir(path):
raise
raise
try:
with open(self.__loc, 'w') as f:
yaml.dump(self.kbo_list, f)
Expand All @@ -824,6 +852,7 @@ def __save_cache(self):
def _clear_cache(self):
if os.path.isfile(self.__loc):
os.remove(self.__loc)
self.kbo_list = []

def _keyboard_list(self,):
kb_names = []
Expand Down Expand Up @@ -913,8 +942,7 @@ def __set_dirs(self):
pref_yaml = os.path.join(defaults.src, 'pref.yaml')
with open(pref_yaml, 'r') as f:
self.dirs = yaml.load(f)

self.console.note(['─────────────────────────────────────────────────────────────────', 'Using preferences from '+pref_yaml, '--reset to reset to defaults'])
self.console.note([defaults.print_lines, 'Using preferences from '+pref_yaml, '--reset to reset to defaults'])

except FileNotFoundError:
self.__generate_dirs()
Expand All @@ -937,7 +965,7 @@ def __generate_dirs(self):
with open(pref_yaml, 'w') as f:
f.write('# Q2K Folder Locations\n')
yaml.dump(dirs, f, default_flow_style = False)
self.console.note(['─────────────────────────────────────────────────────────────────', 'New pref.yaml generated @ '+pref_yaml])
self.console.note([defaults.print_lines, 'New pref.yaml generated @ '+pref_yaml])

except FileNotFoundError:
self.console.error(['Failed to generate '+pref_yaml])
Expand Down Expand Up @@ -1025,9 +1053,9 @@ def set_kb(self, keyboard='', rev='', keymap='', template=''):
self.build_kb = build_kbo
self.build_rev = build_revo
if rev:
self.console.note(['─────────────────────────────────────────────────────────────────','Building '+keyboard+ os.sep +rev+':'+keymap+':'+template, '─────────────────────────────────────────────────────────────────'])
self.console.note([defaults.print_lines, 'Building '+keyboard+os.sep+rev+':'+keymap+':'+template, defaults.print_lines])
else:
self.console.note(['─────────────────────────────────────────────────────────────────','Building '+keyboard+':'+keymap+':'+template, '─────────────────────────────────────────────────────────────────'])
self.console.note([defaults.print_lines, 'Building '+keyboard+':'+keymap+':'+template, defaults.print_lines])
else:
print_kb_list = ', '.join(self.keyboard_list())
self.console.error(['Invalid Keyboard Name - '+keyboard, 'Valid Names: '+print_kb_list])
Expand Down Expand Up @@ -1510,7 +1538,7 @@ def __create_keyplus_yaml(self, DEBUG=False):
else:
path_list = kblibs + [keymap]
output_path = '_'.join(path_list)
output_yaml = out_dir+output_path+'.yaml'
output_yaml = os.path.join(out_dir, output_path+'.yaml')
if not os.path.exists(out_dir):
try:
os.makedirs(out_dir)
Expand Down Expand Up @@ -1548,4 +1576,3 @@ def q2keyplus_gui(keyboard, rev, keymap, template):
# Uncomment this to run as a traditional python script (Commnand Line Interface)
#if __name__ == '__main__':
#q2keyplus()

Loading

0 comments on commit ea10828

Please sign in to comment.