Skip to content

Commit

Permalink
Merge branch 'main' into safe_devices
Browse files Browse the repository at this point in the history
  • Loading branch information
glipR authored Jun 16, 2021
2 parents 23119b5 + 24008fd commit 99b639f
Show file tree
Hide file tree
Showing 28 changed files with 824 additions and 873 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,6 @@ cython_debug/
ev3sim/user_config.yaml
# Generated logs
ev3sim/logs

# Python embeddable with pip
python_embed*
2 changes: 1 addition & 1 deletion FileAssociation.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ NoBackup:
WriteRegStr HKCR "$R0\DefaultIcon" "" "$R2,0"
Skip:
WriteRegStr HKCR "$R0\shell\open" "" "Open"
WriteRegStr HKCR "$R0\shell\open\command" "" '"$R2" "%1" --open'
WriteRegStr HKCR "$R0\shell\open\command" "" '"$R2" "%1"'

Pop $1
Pop $0
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ global-include *.bot
global-include *.sim
global-include *.png
global-include *.py
graft ev3sim/assets
graft ev3sim/assets
prune venv
48 changes: 27 additions & 21 deletions build_exe.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
import argparse, sys
import PyInstaller.__main__
import os
import shutil
from subprocess import Popen
from ev3sim import __version__

parse = argparse.ArgumentParser()
parse.add_argument("--admin", action="store_true", dest="admin")

res = parse.parse_args(sys.argv[1:])

# First, generate the version file to be used in generation.
with open("version_file_template.txt", "r") as f:
string = f.read().replace("<VERSION_NUMBER>", __version__)
with open("version_file.txt", "w") as f:
f.write(string)

# Then generate the build.
PyInstaller.__main__.run(
[
"-y",
"executable_entry.spec",
]
)
if os.path.exists("dist"):
shutil.rmtree("dist")
os.makedirs("dist", exist_ok=True)
os.makedirs("dist/ev3sim", exist_ok=True)
if os.path.exists("dist/python_embed"):
shutil.rmtree("dist/python_embed")
shutil.copytree("python_embed-32", "dist/python_embed")

import os
if os.path.exists("dist/ev3sim/user_config.yaml"):
os.remove("dist/ev3sim/user_config.yaml")

process = Popen("makensis config.nsi")
process.wait()
shutil.move("installer.exe", "installer-32bit.exe")

if os.path.exists("dist"):
shutil.rmtree("dist")
os.makedirs("dist", exist_ok=True)
os.makedirs("dist/ev3sim", exist_ok=True)
if os.path.exists("dist/python_embed"):
shutil.rmtree("dist/python_embed")
shutil.copytree("python_embed-64", "dist/python_embed")

if os.path.exists("dist/ev3sim/ev3sim/user_config.yaml"):
os.remove("dist/ev3sim/ev3sim/user_config.yaml")
if os.path.exists("dist/ev3sim/user_config.yaml"):
os.remove("dist/ev3sim/user_config.yaml")

if res.admin:
process = Popen("makensis config.nsi")
else:
process = Popen("makensis config-no-admin.nsi")
process = Popen("makensis config.nsi")
process.wait()
shutil.move("installer.exe", "installer-64bit.exe")
124 changes: 0 additions & 124 deletions config-no-admin.nsi

This file was deleted.

87 changes: 37 additions & 50 deletions config.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,20 @@
;Includes
!include MUI2.nsh
!include "FileAssociation.nsh"
RequestExecutionLevel admin

;---------------------------------
;About
Name "EV3Sim"
OutFile "one_click.exe"
OutFile "installer.exe"
Unicode true
InstallDirRegKey HKCU "Software\EV3Sim" ""
Var IsAdminMode
Var oldDir
!macro SetAdminMode
StrCpy $IsAdminMode 1
SetShellVarContext All
!macroend
!macro SetUserMode
StrCpy $IsAdminMode 0
SetShellVarContext Current
!macroend

Var ExeLocation

Function .onInit
StrCpy $oldDir "$Programfiles\$(^Name)"
; Need to do this before SetShellVarContext
StrCpy $InstDir "$LocalAppData\$(^Name)"
UserInfo::GetAccountType
Pop $0
${IfThen} $0 != "Admin" ${|} Goto setmode_currentuser ${|}

!insertmacro SetAdminMode
Goto finalize_mode

setmode_currentuser:
!insertmacro SetUserMode

finalize_mode:
StrCpy $ExeLocation "$InstDir\python_embed\Scripts\ev3sim.exe"
SetShellVarContext Current
FunctionEnd

;---------------------------------
Expand Down Expand Up @@ -63,7 +43,7 @@ FunctionEnd
!define MUI_INSTFILESPAGE_ABORTHEADER_TEXT "Installation Aborted."

!define MUI_FINISHPAGE_TITLE "All Done!"
!define MUI_FINISHPAGE_RUN "$InstDir\ev3sim.exe"
!define MUI_FINISHPAGE_RUN "$ExeLocation"
!define MUI_FINISHPAGE_SHOWREADME "https://ev3sim.mhsrobotics.club/"
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Go to documentation."
Expand All @@ -88,42 +68,49 @@ FunctionEnd
;---------------------------------
;Sections
Section "Dummy Section" SecDummy
; Remove previous installation
IfFileExists "$InstDir\python_embed\Lib\site-packages\ev3sim\user_config.yaml" update no_update
update:
CopyFiles "$InstDir\python_embed\Lib\site-packages\ev3sim\user_config.yaml" "$InstDir\default_config.yaml"
no_update:
RMDir /r "$InstDir\python_embed"
SetOutPath "$InstDir"
File /nonfatal /a /r "dist\ev3sim\"
File /nonfatal /a /r "dist\"
WriteRegStr HKCU "Software\EV3Sim" "" $InstDir
IfFileExists "$InstDir\ev3sim\user_config.yaml" update
;Generate the default user config if not in update.
CopyFiles "$InstDir\ev3sim\presets\default_config.yaml" "$InstDir\ev3sim\user_config.yaml"
update:
; Check for old installation in program files.
${IfThen} $IsAdminMode == 0 ${|} Goto after_previous_install ${|}
IfFileExists "$oldDir\ev3sim\user_config.yaml" next_step after_previous_install
next_step:
; Keep old settings and remove the install directory.
CopyFiles "$oldDir\ev3sim\user_config.yaml" "$InstDir\ev3sim\user_config.yaml"
Delete /REBOOTOK "$InstDir\Uninstall.exe"
RMDir /R /REBOOTOK "$oldDir"
;Remove Start Menu launcher
Delete /REBOOTOK "$SMPROGRAMS\MHS_Robotics\EV3Sim.lnk"
;Try to remove the Start Menu folder - this will only happen if it is empty
RMDir /R /REBOOTOK "$SMPROGRAMS\MHS_Robotics"
after_previous_install:

;Run pip install process. pythonw seems to not finish correctly, and so ev3sim doesn't get installed.
;To use test.pypi: '"$InstDir\python_embed\python.exe" -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple ev3sim==2.1.8.post1'
ExecDos::exec '"$InstDir\python_embed\python.exe" -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org ev3sim' "" "$InstDir\pip.log"
Pop $0
StrCmp "0" $0 fine

MessageBox MB_OK "Installation failed, check '$InstDir\pip.log'"
Quit

fine:

;Do user_config stuff
IfFileExists "$InstDir\default_config.yaml" second_update
CopyFiles "$InstDir\python_embed\Lib\site-packages\ev3sim\presets\default_config.yaml" "$InstDir\default_config.yaml"
second_update:
CopyFiles "$InstDir\default_config.yaml" "$InstDir\python_embed\Lib\site-packages\ev3sim\user_config.yaml"

;Start Menu
createDirectory "$SMPROGRAMS\MHS_Robotics"
createShortCut "$SMPROGRAMS\MHS_Robotics\EV3Sim.lnk" "$InstDir\ev3sim.exe" "" "$InstDir\ev3sim.exe" 0
createShortCut "$SMPROGRAMS\MHS_Robotics\EV3Sim.lnk" "$ExeLocation" "" "$ExeLocation" 0
;File Associations
;URL associations for custom tasks.
WriteRegStr HKCR "ev3simc" "" "URL:ev3simc Protocol"
WriteRegStr HKCR "ev3simc" "URL Protocol" ""
WriteRegStr HKCR "ev3simc\shell" "" ""
WriteRegStr HKCR "ev3simc\DefaultIcon" "" "$InstDir\ev3sim.exe,0"
WriteRegStr HKCR "ev3simc\DefaultIcon" "" "$ExeLocation,0"
WriteRegStr HKCR "ev3simc\shell\open" "" ""
WriteRegStr HKCR "ev3simc\shell\open\command" "" '"$InstDir\ev3sim.exe" "%l" --custom-url'
WriteRegStr HKCR "ev3simc\shell\open\command" "" '"$ExeLocation" "%l" --custom-url'
;Open sims by default.
${registerExtensionOpen} "$InstDir\ev3sim.exe" ".sim" "ev3sim.sim_file"
${registerExtensionEdit} "$InstDir\ev3sim.exe" ".sim" "ev3sim.sim_file"
${registerExtensionOpen} "$ExeLocation" ".sim" "ev3sim.sim_file"
${registerExtensionEdit} "$ExeLocation" ".sim" "ev3sim.sim_file"
;Open bots by default.
${registerExtensionOpen} "$InstDir\ev3sim.exe" ".bot" "ev3sim.bot_file"
${registerExtensionOpen} "$ExeLocation" ".bot" "ev3sim.bot_file"
;Create uninstaller
WriteUninstaller "$InstDir\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EV3Sim" "DisplayName" "EV3Sim - Robotics Simulator"
Expand Down
22 changes: 22 additions & 0 deletions creating_embed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Creating the python embed folder

First, Ensure you have the matching python installed locally, as you'll need to copy some files over.

1. Download get-pip.py and run `python get-pip.py`.
2. Change the contents of `python39._pth` to

```
python39.zip
.
.\Lib
.\Lib\site-packages
# Uncomment to run site.main() automatically
#import site
```

3. Copy `tcl` to `tcl` (Local install to embed)
4. Copy `Lib/tkinter` to `Lib/tkinter` (Local install to embed)
5. Copy `DLLs/_tkinter.pyd`, `DLLs/tcl86t.dll`, `DLLs/tk86t.dll` to `_tkinter.pyd`, ... (NOT in DLLs folder in embed)

After this, `python -m build_exe` should generate a good installer.
3 changes: 3 additions & 0 deletions ev3sim/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ev3sim.entry import main

main()
2 changes: 1 addition & 1 deletion ev3sim/batched_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def simulate(batch_file, preset_filename, bot_paths, seed, override_settings, *q
initialiseFromConfig(config, send_queues, recv_queues)


def batched_run(batch_file, bind_addr, seed):
def batched_run(batch_file, seed):

with open(batch_file, "r") as f:
config = yaml.safe_load(f)
Expand Down
2 changes: 2 additions & 0 deletions ev3sim/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@

# Command information
EV3SIM_BOT_COMMAND = "EV3SIM_BOT_COMMAND"
EV3SIM_PRINT = "EV3SIM_PRINT"
EV3SIM_MESSAGE_POSTED = "EV3SIM_MESSAGE_POSTED"
Loading

0 comments on commit 99b639f

Please sign in to comment.