Skip to content

Blocklyprop Solo Rest API compatibility #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 208 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
1393724
Convert to Cloud-compiling
michel-cf Sep 26, 2015
9eed203
Cleaning up imports
michel-cf Sep 26, 2015
119f21f
Fix errors
michel-cf Sep 26, 2015
6b73543
Load binary
michel-cf Sep 27, 2015
dd510a6
Remove libraries from buildfile
michel-cf Oct 18, 2015
3aacf62
Fix Mac version
michel-cf Dec 22, 2015
1104bf4
Merge branch 'TK-Cloud-compile' of https://github.com/parallaxinc/Blo…
michel-cf Dec 22, 2015
8914c6f
Replace icon, and include about page
michel-cf Feb 14, 2016
78680fd
Add success field to load response
michel-cf Feb 15, 2016
a2a07b1
Fix MacOS version
michel-cf Feb 15, 2016
93dfcc1
Change BlocklyProp url
michel-cf Feb 28, 2016
afd9676
Windows installer script
michel-cf Jul 9, 2016
d51459c
Improved Windows installer: start menu shortcut
michel-cf Jul 9, 2016
711cade
Installer
michel-cf Jul 16, 2016
5939a77
Fix numeric 13 that got converted to newline
michel-cf Jul 16, 2016
76f879c
Background image for windows installer
michel-cf Jul 17, 2016
c522806
Fix linux spec file and allow working on other then localhost
Jul 20, 2016
ecd215a
Add baudrate support and increase version
michel-cf Aug 23, 2016
03463ba
Merged branch TK-Cloud-compile into TK-Cloud-compile
michel-cf Aug 23, 2016
4cbf4fb
Merge
michel-cf Aug 23, 2016
14b8bb4
Remove c libs
michel-cf Aug 23, 2016
be04b93
Increase app version in installer
michel-cf Aug 24, 2016
0265fa2
Merge pull request #25 from michel-cf/demo
zfi Aug 25, 2016
8f8ac39
Filter out Bluetooth ports
michel-cf Sep 12, 2016
8e4d407
Increase version in about dialog
Sep 13, 2016
793ad64
Add exception handling around call to get the user IP address.
pjewald Feb 1, 2017
89797e8
Change origin repo from parallaxinc to zfi
pjewald Feb 1, 2017
545165a
Merge pull request #30 from zfi/demo
paragitadmin Feb 1, 2017
57c429c
Updated version (v0.5.1) and copyright in About text
jeffam70 Feb 2, 2017
29c1cac
Merge pull request #31 from PropGit/demo
PropGit Feb 2, 2017
a3ff6fa
Increase version to match about file
michel-cf Feb 2, 2017
637a60f
Add generic BlocklyPropClient installer file.
pjewald Feb 8, 2017
04cccc1
Merge branch 'demo' of github.com:zfi/BlocklyPropClient into demo
pjewald Feb 8, 2017
ad336ad
Add basic file logging to the BP main. Log file is overwritten on ea…
pjewald Feb 8, 2017
96ba217
[Untested] Moved packaging/installer resources under package subfolde…
PropGit Feb 8, 2017
c3bb536
Replace broken propeller-load file.
pjewald Feb 9, 2017
a687a76
Add error handling to system calls that were verifying FTDI driver op…
pjewald Feb 9, 2017
3ca0361
Merge pull request #36 from zfi/demo
zfi Feb 9, 2017
3076954
Updated README.md to include configuration and build steps from Windo…
PropGit Feb 9, 2017
2b53f39
Merge remote-tracking branch 'parallax/demo' into BuildAndPackage
PropGit Feb 9, 2017
b18726e
Fixed Windows build steps, Tested build and package on Win 64-bit.
PropGit Feb 10, 2017
9fa4366
Merge pull request #40 from PropGit/BuildAndPackage
paragitadmin Feb 10, 2017
754cefd
Add stub code for macos support
pjewald Feb 10, 2017
8bef1ca
Set all .specs to turn off UPX; it's outdated, unsupported, and not v…
PropGit Feb 10, 2017
9a3c879
[Untested] Removed Mac FTDI Installer to be later replaced by kext, u…
PropGit Feb 10, 2017
3770138
Create BlocklyHardware and moved FTDI detection code from BlocklyLogg…
pjewald Feb 10, 2017
ff6f638
Merge pull request #41 from zfi/demo
paragitadmin Feb 10, 2017
d412292
Updated .gitignore to exclude local VPython folder
PropGit Feb 10, 2017
dce1a00
Updated .gitignore to exclude local VPython/ virtual environment folder
PropGit Feb 10, 2017
67e8bca
Added drivers/FTDIUSBSerialDriver.kext in prep for Mac build script.
PropGit Feb 10, 2017
44e006d
Updated macsignedpack.sh permissions to executable.
PropGit Feb 11, 2017
66d11f8
Fixed macsignedpack.sh bugs and optimized messages and processing. T…
PropGit Feb 11, 2017
ee8bdd7
Change macsignedpack script to mac_app_sign_and_package, updated comm…
PropGit Feb 11, 2017
3d03369
Tested mac_app_sign_and_package script up to signing. Has output pro…
PropGit Feb 11, 2017
f57c49c
[UNTESTED] Moved more INFO blocks together, reformatted some messages…
PropGit Feb 12, 2017
9fffc74
Fixed smart-quote bug.
PropGit Feb 12, 2017
1378b95
Rearranged option order and changed INFO block to RECIPE block.
PropGit Feb 12, 2017
cc91a83
Cleaned up and made output more consistent.
PropGit Feb 12, 2017
cacd8bf
More script cleanup.
PropGit Feb 12, 2017
4bcece0
Updated .gitignore to exclude application bundles and packages, in ca…
PropGit Feb 12, 2017
3d18542
[final product build doens't include package]
PropGit Feb 12, 2017
c77d174
Fixed incorrect package path.
PropGit Feb 12, 2017
293df98
Improved the comments at the top of the mac_sign... script
PropGit Feb 12, 2017
163e725
Improved examples in usage comments.
PropGit Feb 12, 2017
243d10e
Updated README.md to include sign_and_package script instructions.
PropGit Feb 13, 2017
fa7fd6b
Fixed error in instructions; also noted need for signing certificate.
PropGit Feb 13, 2017
0f4cf49
Merge remote-tracking branch 'parallax/demo' into BuildAndPackage in …
PropGit Feb 13, 2017
ec2e29f
Merge branch 'BuildAndPackage' into demo
PropGit Feb 13, 2017
2848f1c
Updated the file logging for macos to create log file in the /tmp dir…
pjewald Feb 13, 2017
ec7d18c
Add file update missing from last commit
pjewald Feb 13, 2017
bce031e
Merge pull request #43 from zfi/demo
PropGit Feb 13, 2017
4e2ec24
Merge pull request #42 from PropGit/demo
PropGit Feb 13, 2017
3879c5f
Set newly-found UPX switches to False.
PropGit Feb 13, 2017
b8c8bab
Merge pull request #44 from PropGit/BuildAndPackage
PropGit Feb 14, 2017
9339e80
Removed scripts.txt temp file and bumped the version up to 0.5.2.
PropGit Feb 14, 2017
244cda5
Merge branch 'BuildAndPackage' into demo
PropGit Feb 14, 2017
a553870
Merge pull request #46 from PropGit/demo
PropGit Feb 14, 2017
a0cd242
Add support for placing the log file on a Windows system.
pjewald Feb 14, 2017
9cff8f7
Merge pull request #48 from zfi/170214-WindowsLogging
PropGit Feb 15, 2017
7c74b74
Correct error in Windows default log file location.
pjewald Feb 15, 2017
9b84f04
Merge pull request #49 from zfi/demo
zfi Feb 15, 2017
e11da70
Add code block to set Linux logging location.
pjewald Feb 15, 2017
b071aba
Merge pull request #50 from zfi/demo
zfi Feb 15, 2017
2ccd88f
Add code to detect FTDI driver state for Windows.
pjewald Feb 15, 2017
cffe447
Merge pull request #51 from zfi/demo
zfi Feb 15, 2017
f0567f1
Replaced /drivers/FTDIUSBSerialDriver.kext because InfoPList.strings …
PropGit Feb 17, 2017
a9e49eb
Bumped version to v0.5.3
PropGit Feb 17, 2017
d323538
Merge remote-tracking branch 'parallax/demo' into demo
PropGit Feb 17, 2017
3e52cc9
Add logging code to serial port configuration.
pjewald Feb 21, 2017
5d30539
Merge pull request #58 from zfi/demo
zfi Feb 21, 2017
2683df8
Correct error intorduced when application version moved from two elem…
pjewald Feb 22, 2017
5ccc17e
Handle unintended consequence of changing the version number from two…
pjewald Feb 22, 2017
f0e02f1
Merge pull request #59 from zfi/demo
zfi Feb 22, 2017
69599be
Add logging to loader code to understand when the full loader path is…
pjewald Feb 22, 2017
e35e26a
Merge pull request #60 from zfi/demo
zfi Feb 22, 2017
2601d7e
Add code to detect condition where no serial ports have been detected.
pjewald Feb 22, 2017
5e12394
Merge pull request #61 from zfi/demo
zfi Feb 22, 2017
57d1299
Add logging code to help determine why serial port appears to 'go awa…
pjewald Feb 22, 2017
2939f70
Merge pull request #62 from zfi/demo
zfi Feb 22, 2017
c0e009f
Bumping up version to 0.5.3.
pjewald Feb 23, 2017
4f07738
Merge pull request #64 from zfi/demo
zfi Feb 23, 2017
af6bd39
Add a string application version. Add code comments.
pjewald Feb 23, 2017
1e9c4e4
Merge pull request #65 from zfi/demo
zfi Feb 23, 2017
f3cc093
Add setup and run instructions for Linux
zfi Feb 25, 2017
6150123
Added BlocklyPropClient.icns and Info.plist to mac-resources for buil…
PropGit Mar 1, 2017
7628b0c
Merge remote-tracking branch 'parallax/demo' into BuildAndPackage
PropGit Mar 1, 2017
918b60a
Auto-created new BlocklyPropClient.spec that properly builds an app b…
PropGit Mar 1, 2017
d0d69a8
Moved BlocklyPropClient.icns out to root. Deleted the Info.plist fil…
PropGit Mar 1, 2017
4e4c998
Updated README.md with BlocklyPropClient.macos.spec Details.
PropGit Mar 1, 2017
f07aaa4
Fixed accidental headers in code listing at bottom of README.md
PropGit Mar 1, 2017
6990855
Another attempt to fix formatting at the bottom of README.md
PropGit Mar 1, 2017
e348a1f
And another attempt to fix formatting at the bottom of README.md
PropGit Mar 1, 2017
e42e6cb
Hopefully the last attempt to fix formatting at the bottom of README.md
PropGit Mar 1, 2017
29979aa
Added version to .spec file.
PropGit Mar 1, 2017
5d7161c
Merge remote-tracking branch 'origin/BuildAndPackage' into BuildAndPa…
PropGit Mar 1, 2017
e9fcfb3
Updated .spec details in README.md
PropGit Mar 1, 2017
99b0c1c
Made .spec the official .macos.spec.
PropGit Mar 1, 2017
0752204
Merge remote-tracking branch 'parallax/demo' into demo
PropGit Mar 1, 2017
f2a5348
Merge branch 'BuildAndPackage' into demo
PropGit Mar 1, 2017
227098a
Add more console logging to the logging setup code.
pjewald Mar 1, 2017
30fb74a
Merge branch 'demo' of github.com:zfi/BlocklyPropClient into demo
pjewald Mar 1, 2017
6731b65
Merge branch 'demo' of github.com:parallaxinc/BlocklyPropClient into …
pjewald Mar 1, 2017
7e16e6e
Merge pull request #68 from zfi/demo
zfi Mar 1, 2017
0cce8ca
Merge pull request #67 from PropGit/demo
PropGit Mar 1, 2017
e3f8406
Updated Mac Installer background image.
PropGit Mar 1, 2017
74eb91f
Correct a condition where path to log file was not being created and …
pjewald Mar 1, 2017
c382a23
Merge branch '20170301-MacOS-Logging' into demo
pjewald Mar 1, 2017
1cc535e
Merge pull request #70 from zfi/demo
zfi Mar 1, 2017
db71c47
Merge remote-tracking branch 'parallax/demo' into demo
PropGit Mar 1, 2017
f5adbda
Updated Mac Installer background to a lighter color.
PropGit Mar 1, 2017
728590f
Merge pull request #71 from PropGit/demo
PropGit Mar 1, 2017
e3bbb93
Removed manual CFBundleShortVersionString from macos.spec (it default…
PropGit Mar 2, 2017
2055266
Merge branch 'BuildAndPackage' into demo
PropGit Mar 2, 2017
9b9dfa3
Created first draft of set_version script to update multiple file's v…
PropGit Mar 2, 2017
cf21231
Fixed spacing problem in variable names caused by copy and paste.
PropGit Mar 2, 2017
a2fc3bf
Enhanced script to accept version number argument.
PropGit Mar 2, 2017
d351215
Updated set_version usage notes.
PropGit Mar 2, 2017
26eb517
Fixed Parallax name error in Windows' .iss file. Fixed Ubuntu-incomp…
Mar 3, 2017
31df15a
Final touches on set_version script notes.
PropGit Mar 3, 2017
ad710b4
Added format notes in set_version script.
Mar 3, 2017
97cc445
Enhanced mac_app_sign script to handle potential bundle versioning er…
Mar 3, 2017
b0d7556
Merge pull request #74 from PropGit/demo
PropGit Mar 6, 2017
21cca01
Bumped version number to v0.5.4
PropGit Mar 6, 2017
fa759b8
Merge pull request #75 from PropGit/demo
PropGit Mar 6, 2017
71f6669
Add more debugging code to track failed propeller-load launch under M…
pjewald Mar 7, 2017
3adcc2c
Merge pull request #77 from zfi/demo
zfi Mar 7, 2017
9aac303
Fixed mistake in mac_app... script that left backup Info.plist file i…
PropGit Mar 8, 2017
77450da
Merge pull request #78 from PropGit/demo
PropGit Mar 8, 2017
59ffad5
Update README.md
PropGit Mar 9, 2017
eec3a9e
Merge pull request #81 from PropGit/demo
PropGit Mar 9, 2017
45ac7bd
Replaced .linux.spec to fix build problem and add about.txt to the di…
Mar 16, 2017
8d4146c
Updated self.appdir code to try one or two methods of finding working…
Mar 16, 2017
02c380b
Enhanced self.appdir code to take care of both blank launch path as w…
PropGit Mar 16, 2017
eddea09
Merge pull request #83 from PropGit/LinuxFix
zfi Mar 16, 2017
6bcf420
Replaced all platform's propeller-load with proploader. Adjusted uns…
Mar 16, 2017
4fa654c
Partially coded to add Wi-Fi ports
Mar 21, 2017
971ef4f
Enhanced to find and get names from multiple Wi-Fi Modules.
Mar 21, 2017
0841550
Correct bug: wports should be self.wports. Working on matching Wi-Fi…
Mar 21, 2017
5e97897
Enhanced to match Wi-Fi Name to IP Address for download purposes. Th…
Mar 22, 2017
426edfc
Sorted Wi-Fi port names.
Mar 22, 2017
c726fb4
In process of refactoring PropellerLoad.
Mar 22, 2017
8a029e8
Replaced errant tab characters with spaces
Mar 22, 2017
d70d042
Fixed bug preventing call to loader().
Mar 22, 2017
82a348c
Some refactoring. Nearly have updated download function working.
Mar 23, 2017
055bf4e
More attempts to finish download function. Doesn't work.
Mar 23, 2017
78bd4b1
More fixed that don't work.
Mar 23, 2017
bdcd65a
Fixed download list and related code to work properly. Tested port r…
Mar 23, 2017
8b0e22a
Made success, out, err more clearly a list of results.
Mar 23, 2017
4206599
[Issue #57] Fixed server string format error. No more annoying Value…
Mar 24, 2017
c0d9c6a
Merge pull request #85 from PropGit/demo
paragitadmin Mar 24, 2017
eb179bd
Update WiFi development branch with upstream demo branch.
Mar 24, 2017
407383d
Enhanced comments, updated 'Add requested port' routine to take first…
Mar 24, 2017
83f8961
Removed old unused resource_path(relative) function.
Mar 24, 2017
aba7385
Updated version to v0.6.0
Mar 28, 2017
ce6b841
Updated PropLoader to v1.0-29
PropGit Mar 31, 2017
f7682cf
Updated version to 0.6.1.
Mar 31, 2017
58eb2fc
Fixed mistake in PropellerLoad that left loading flag true. Bumped v…
PropGit Apr 3, 2017
15b3fe0
Merge pull request #87 from PropGit/WiFi
PropGit Apr 4, 2017
9ead61d
Updated PropLoader to v1.0-33.
PropGit May 2, 2017
a7ce8c0
Sorted wired ports alphanumerically, but kept wired ports at top of l…
May 3, 2017
21b9803
Fixed bug in strAfter that truncated the last character from the string.
May 5, 2017
c1b34bf
Added updateWiFiPorts and enterUniqueWiFiPorts to PropellerLoad to ma…
May 5, 2017
f16d2bf
Merge branch 'demo' into WiFi to update PropLoader and com port sorting.
May 5, 2017
77d2dd6
Major refactoring to combine wired and wireless port history list int…
May 5, 2017
856a95e
Fixed bug in download() that mistakenly compared com_port against ent…
May 5, 2017
bd99843
Fixed potential bug in enterUniqueWiFiPort.
May 6, 2017
e2d866f
Bumped version to v0.6.3.
May 6, 2017
ae78b6e
Merge pull request #95 from PropGit/demo
PropGit May 8, 2017
5cc423c
Merge pull request #96 from PropGit/WiFi
PropGit May 8, 2017
34ae16f
Updated proploader to v1.0-34 and bumped client version to v0.6.4
PropGit Sep 19, 2017
2a18755
Merge pull request #102 from PropGit/Demo
PropGit Sep 26, 2017
ca1b148
Updated Windows installer script to run embedded Parallax USB Driver …
PropGit Sep 28, 2017
4bfb8db
Merge pull request #103 from PropGit/demo
PropGit Sep 28, 2017
5fb3912
Removed version from the package name created by the Mac platform pac…
PropGit Sep 28, 2017
5ebd3c0
Merge pull request #104 from PropGit/demo
PropGit Sep 28, 2017
524c8a6
Bumped version to v0.7.0. Enhanced to b64-encode transmissions to we…
Dec 13, 2017
023dc61
Updated PropLoader to v1.0-37. Automatically steps-down baudrate for…
Dec 14, 2017
04109cc
Merge pull request #105 from PropGit/encode_64
PropGit Dec 14, 2017
fa9dc23
Merge pull request #106 from PropGit/proploader_1_037
PropGit Dec 14, 2017
e38f3b9
Fixed permissions on Mac's proploader; it wasn't executable.
PropGit Dec 15, 2017
7fa02c2
Merge pull request #107 from PropGit/demo
PropGit Dec 15, 2017
0e2f51d
Added 'loader-options' to accept -c and/or -v (CODE/VERBOSE/CODE_VERO…
Dec 20, 2017
32e4f2a
Bumped version to v0.7.5.
Dec 20, 2017
dca1f26
Enhanced to deliver version as a string to communicate version as maj…
Dec 20, 2017
44ee2c5
Fixed comment.
Dec 21, 2017
72f2bbb
Merge pull request #108 from PropGit/results_simplify
PropGit Dec 29, 2017
4433900
BlocklyProp Solo API support
pbeyl May 6, 2022
52dbb86
Handle terminal input
pbeyl May 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
####################
## BlocklyPropClient
####################
access.txt
venv/
VPython/
*.app
*.pkg
*.bak

#################
## Eclipse
Expand Down
132 changes: 132 additions & 0 deletions BlocklyHardware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import os
import logging
from sys import platform
from subprocess import Popen, PIPE, check_output, CalledProcessError

# Platform constants
PLATFORM_LINUX = 'linux2'
PLATFORM_MACOS = 'darwin'
PLATFORM_WINDOWS = 'win32'

# Define error constants
FTDI_DRIVER_NOT_INSTALLED = 201
FTDI_DRIVER_NOT_LOADED = 202
PLATFORM_UNKNOWN = 2


# Enable logging
__module_logger = logging.getLogger('blockly')


def init():
result = is_module_installed()
if result != 0:
return result

result = is_module_loaded()
if result != 0:
return result


def is_module_installed():
if platform == PLATFORM_MACOS:
return __is_module_installed_macos()
elif platform == PLATFORM_LINUX:
return __is_module_installed_linux()
elif platform == PLATFORM_WINDOWS:
return __is_module_installed_windows()
else:
return PLATFORM_UNKNOWN


def is_module_loaded():
if platform == PLATFORM_MACOS:
return __is_module_loaded_macos()
elif platform == PLATFORM_LINUX:
return __is_module_loaded_linux()
else:
return PLATFORM_UNKNOWN


# Ubuntu implementation
def __is_module_installed_linux():
try:
process = Popen(['cat', '/proc/modules'], stdout=PIPE, stderr=PIPE)
output = check_output(('grep', 'ftdi'), stdin=process.stdout)
__module_logger.debug('FTDI module load state')
__module_logger.debug(output)
return 0
except CalledProcessError:
__module_logger.warning('No FTDI modules detected.')
return FTDI_DRIVER_NOT_INSTALLED


def __is_module_loaded_linux():
try:
process = Popen(['dmesg', '-H', '-x'], stdout=PIPE, stderr=PIPE)
output = check_output(('grep', 'ftdi'), stdin=process.stdout)
process.wait()
__module_logger.debug(output)
return 0
except CalledProcessError:
__module_logger.warning('Serial port is not assigned.')
return FTDI_DRIVER_NOT_LOADED


# MacOS implementation
def __is_module_installed_macos():
try:
# Does the log directory exist
os.stat('/Library/Extensions/FTDIUSBSerialDriver.kext')
__module_logger.info('FTDI driver is installed')
return 0

except OSError:
__module_logger.error('Cannot find FTDI installation')
return FTDI_DRIVER_NOT_INSTALLED


def __is_module_loaded_macos():
try:
process = Popen(['kextstat'], stdout=PIPE, stderr=PIPE)
output = check_output(('grep', 'FTDI'), stdin=process.stdout)
__module_logger.debug('FTDI module load state')
__module_logger.debug(output)
return 0
except CalledProcessError:
__module_logger.warning('No FTDI modules detected.')
return 1


# Windows implementation
def __is_module_installed_windows():
try:
out, err = Popen('driverquery.exe -v', stdout=PIPE, shell=True).communicate()
position = out.find('FT')
if position > 0:
__module_logger.debug('FTDI module load state')
__module_logger.debug(out[position:position+91])
return 0
else:
__module_logger.warning('No FTDI modules installed.')
return FTDI_DRIVER_NOT_INSTALLED
except CalledProcessError:
__module_logger.warning('No FTDI modules detected.')
return FTDI_DRIVER_NOT_INSTALLED


def __is_module_loaded_windows():
try:
out, err = Popen('driverquery.exe -v', stdout=PIPE, shell=True).communicate()
position = out.find('FT')
if position > 0:
__module_logger.debug('FTDI module load state')
__module_logger.debug(out[position+84:position+91])
return 0
else:
__module_logger.warning('No FTDI modules loaded.')
return FTDI_DRIVER_NOT_INSTALLED
except CalledProcessError:
__module_logger.warning('No FTDI modules detected.')
return FTDI_DRIVER_NOT_INSTALLED

198 changes: 198 additions & 0 deletions BlocklyLogger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
""""
BlocklyPropLogger manages the application logging process.


"""

import os
import logging
import platform


__author__ = 'Jim Ewald'


# Platform constants
PLATFORM_POSIX = "posix"
PLATFORM_LINUX = 'Linux'
PLATFORM_MACOS = 'MacOS'
PLATFORM_DARWIN = 'Darwin'
PLATFORM_WINDOWS = 'Windows'

# Default log path for each platform
DEFAULT_PATH_MACOS = 'Library/Logs/Parallax'
DEFAULT_PATH_WINDOWS = 'AppData/Local/Parallax'
DEFAULT_PATH_LINUX = 'tmp'

# Resulting path for log file
path = None

loglevel = logging.DEBUG


def init(filename = 'BlocklyPropClient.log'):
global path

# Set NullHandler as a default
try: # Python 2.7+
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass

logging.getLogger(__name__).addHandler(NullHandler())

# Set a default log file name
logfile_name = filename
disable_filelogging = False

# Set correct log file location
system = platform.system()
print("Platform detected is: %", system)

# A posix system could be a MacOS or a Linux variety
if system == PLATFORM_POSIX:
# Asking for a MacOS version number only works on MacOS
is_mac = platform.mac_ver()
if is_mac[0] == "":
# This must be a Linux platform
system = PLATFORM_LINUX
else:
system = PLATFORM_MACOS

if (system == PLATFORM_MACOS) or (system == PLATFORM_DARWIN):
logfile_name = __set_macos_logpath(filename)
elif system == PLATFORM_WINDOWS:
logfile_name = __set_windows_logpath(filename)
elif system == PLATFORM_LINUX:
logfile_name = __set_linux_logpath(filename)

# Verify that we have a valid location
if logfile_name is None:
disable_filelogging = True
else:
# Set the module-level path
path = logfile_name
print("Sending file logging output to: ", path)

# Create a logger
logger = logging.getLogger('blockly')
logger.setLevel(loglevel)

# create a console handler for error-level events
console = logging.StreamHandler()
console.setLevel(loglevel)

# create a logging format
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console.setFormatter(formatter)

# create a file handler to log events to the debug level if disk logging is active.
# Log file is overwritten each time the app runs.
if not disable_filelogging:
handler = logging.FileHandler(logfile_name, mode='w')
handler.setLevel(loglevel)
handler.setFormatter(formatter)
logger.addHandler(handler)

# add the handlers to the logger
logger.addHandler(console)
logger.info("Logger has been started.")


# Set the default log file location on a Linux system
def __set_linux_logpath(filename):
user_home = os.path.expanduser('~')
print("User home directory is: %s", user_home)
log_path = user_home + "/" + DEFAULT_PATH_LINUX
print("Logfile path is %s", log_path)

# Does the log directory exist
try:
result = __verify_logpath(log_path)
if result is None or result == False:
# Path does not exist. Create it
if __create_logpath(log_path) is None:
return None
else:
return log_path + '/' + filename

except OSError:
return None


# Set the default log file location on a MacOS system
def __set_macos_logpath(filename):
user_home = os.path.expanduser('~')
print("User home directory is: %s", user_home)
log_path = user_home + "/" + DEFAULT_PATH_MACOS
print("Logfile path is %s", log_path)

# Does the log directory exist
try:
result = __verify_logpath(log_path)
if result is None or result == False:
# Path does not exist. Let's create it
if __create_logpath(log_path) is None:
# Try to create the directory in the tmp directory
log_path = '/tmp'
result = __verify_logpath(log_path)
if result is None:
return None

return log_path + '/' + filename
except OSError:
return None


# Set the default log file location on a Windows system
def __set_windows_logpath(filename):
user_home = os.path.expanduser('~')
print("User home directory is: %s", user_home)
log_path = user_home + "/" + DEFAULT_PATH_WINDOWS
print("Log file path is: %s", log_path)

# Does the log directory exist
try:
result = __verify_logpath(log_path)

if result is None or result == False:
# Path does not exist. Create it
if __create_logpath(log_path) is None:
# try to create the log file in the user's home directory
log_path = user_home
result = __verify_logpath(log_path)

if result is None:
return None

return log_path + '/' + filename
except OSError:
return None


# Create a file path for the log file
def __create_logpath(file_path):
try:
os.makedirs(file_path)
return True

except OSError as ex:
print ex.message
return None


# Verify that the file for the log file exists
def __verify_logpath(file_path):
try:
print("Testing access to: %s", file_path)
return os.access(file_path, os.W_OK)

except OSError as ex:
print ex.message
return None

except Exception as ex:
print ex.message
return None
Binary file added BlocklyPropClient.icns
Binary file not shown.
Loading