Commit 1df3bd21 authored by carlosperate's avatar carlosperate

Restate use of arduexec folder, improve py build and electron file management.

Improve the path creation variable declarations for the python build scripts.
Improve the Electron project finder module.
Update Electron build scripts to use project finder module.
All these changes should simplify the process of changing how the desktop app and server executable folders and files are named.
parent ca0ba142
...@@ -68,10 +68,10 @@ docs/_build/ ...@@ -68,10 +68,10 @@ docs/_build/
#################### ####################
# Project specific # # Project specific #
#################### ####################
# Arduino sketch generated by the application # Arduino sketch generated by the Python server
ArdublocklySketch.ino ArdublocklySketch.ino
# Server App settinsg file generated # Server App settings file generated by the Python server
ServerCompilerSettings.ini ServerCompilerSettings.ini
# Desktop application log file # Desktop application log file
...@@ -81,11 +81,6 @@ ardublockly2.log ...@@ -81,11 +81,6 @@ ardublockly2.log
# Anything starting with this is created as a unit/module testing temporal file # Anything starting with this is created as a unit/module testing temporal file
TestTemp_* TestTemp_*
# CEF cache and log files
webcache
cef_error.log
cef_debug.log
# Miscellaneous files that should not get revisioned # Miscellaneous files that should not get revisioned
/ignore /ignore
...@@ -94,8 +89,6 @@ cef_debug.log ...@@ -94,8 +89,6 @@ cef_debug.log
/upload /upload
/releases /releases
/arduexec /arduexec
/arduexec.app
ardublockly_server_run.*
ardublockly_run.* ardublockly_run.*
# The documentation is built with the GitHub wiki data # The documentation is built with the GitHub wiki data
......
...@@ -28,8 +28,8 @@ Ardublockly.isRunningElectron = function() { ...@@ -28,8 +28,8 @@ Ardublockly.isRunningElectron = function() {
*/ */
Ardublockly.loadJsInElectron = function() { Ardublockly.loadJsInElectron = function() {
if (Ardublockly.isRunningElectron()) { if (Ardublockly.isRunningElectron()) {
var projectRootLocator = require('remote').require('./rootlocator.js'); var projectLocator = require('remote').require('./projectlocator.js');
var projectRoot = projectRootLocator.getProjectRootPath(); var projectRoot = projectLocator.getProjectRootPath();
window.$ = window.jQuery = require(projectRoot + window.$ = window.jQuery = require(projectRoot +
'/ardublockly/js_libs/jquery-2.1.3.min.js'); '/ardublockly/js_libs/jquery-2.1.3.min.js');
window.Hammer = require(projectRoot + '/ardublockly/js_libs/hammer.min.js'); window.Hammer = require(projectRoot + '/ardublockly/js_libs/hammer.min.js');
......
...@@ -31,7 +31,8 @@ except ImportError: ...@@ -31,7 +31,8 @@ except ImportError:
raise SystemExit("You need to have py2exe installed!") raise SystemExit("You need to have py2exe installed!")
exec_folder_name = os.path.join("arduexec", "server") exec_folder_name = "arduexec"
server_exec_folder_name = "server"
script_tag = "[Ardublockly build] " script_tag = "[Ardublockly build] "
script_tab = " " script_tab = " "
...@@ -40,7 +41,8 @@ script_tab = " " ...@@ -40,7 +41,8 @@ script_tab = " "
project_root_dir = \ project_root_dir = \
os.path.dirname( # going up 1 level os.path.dirname( # going up 1 level
os.path.dirname(os.path.realpath(__file__))) # folder dir of this os.path.dirname(os.path.realpath(__file__))) # folder dir of this
executable_dir = os.path.join(project_root_dir, exec_folder_name) server_exec_dir = os.path.join(project_root_dir, exec_folder_name,
server_exec_folder_name)
# Enable the ardublocklyserver package access the sys path for py2exe to find # Enable the ardublocklyserver package access the sys path for py2exe to find
sys.path.append(project_root_dir) sys.path.append(project_root_dir)
...@@ -116,7 +118,7 @@ def get_py2exe_options(): ...@@ -116,7 +118,7 @@ def get_py2exe_options():
# Py2exe options: http://www.py2exe.org/index.cgi/ListOfOptions # Py2exe options: http://www.py2exe.org/index.cgi/ListOfOptions
py2exe_options = { py2exe_options = {
"py2exe": {"dist_dir": executable_dir, "py2exe": {"dist_dir": server_exec_dir,
"compressed": False, "compressed": False,
"bundle_files": 3, "bundle_files": 3,
"skip_archive": True, "skip_archive": True,
...@@ -152,7 +154,7 @@ def create_run_batch_file(): ...@@ -152,7 +154,7 @@ def create_run_batch_file():
entry point built by Electron. entry point built by Electron.
""" """
batch_text = "@echo off\n" + \ batch_text = "@echo off\n" + \
"start %s" % os.path.join("arduexec", "ardublockly.exe") "start %s" % os.path.join(exec_folder_name, "ardublockly.exe")
batch_location = os.path.join(project_root_dir, "ardublockly_run.bat") batch_location = os.path.join(project_root_dir, "ardublockly_run.bat")
try: try:
batch_file = open(batch_location, "w") batch_file = open(batch_location, "w")
...@@ -174,7 +176,7 @@ def main(): ...@@ -174,7 +176,7 @@ def main():
remove_directory(os.path.join(os.getcwd(), "build")) remove_directory(os.path.join(os.getcwd(), "build"))
print(script_tag + "Removing old executable directory.") print(script_tag + "Removing old executable directory.")
remove_directory(executable_dir) remove_directory(server_exec_dir)
print(script_tag + "Building Ardublockly using py2exe.") print(script_tag + "Building Ardublockly using py2exe.")
if len(sys.argv) <= 1: if len(sys.argv) <= 1:
......
...@@ -38,15 +38,8 @@ from glob import glob ...@@ -38,15 +38,8 @@ from glob import glob
spec_coll_name = "server" spec_coll_name = "server"
if platform.system() == "Darwin": exec_folder_name = "arduexec"
# On MacOS the Electron app contents are dumped into the project root py_exec_folder = os.path.join(exec_folder_name, spec_coll_name)
# directory and the entire folder is contained in a
# 'Ardublockly.app/Contents' folder.
exec_folder = ""
else:
# In Windows and Linux the Electron files are located in this folder
exec_folder = "arduexec"
py_exec_folder = os.path.join(exec_folder, "server")
script_tag = "[Ardublockly build] " script_tag = "[Ardublockly build] "
script_tab = " " script_tab = " "
...@@ -56,7 +49,6 @@ project_root_dir = \ ...@@ -56,7 +49,6 @@ project_root_dir = \
os.path.dirname( # going up 1 level os.path.dirname( # going up 1 level
os.path.dirname(os.path.realpath(__file__))) # folder dir of this os.path.dirname(os.path.realpath(__file__))) # folder dir of this
# verbose_print = print if verbose else lambda *a, **k: None # verbose_print = print if verbose else lambda *a, **k: None
...@@ -176,7 +168,7 @@ def create_shell_file(os_type): ...@@ -176,7 +168,7 @@ def create_shell_file(os_type):
shell_text = '#!/bin/bash\n' \ shell_text = '#!/bin/bash\n' \
'DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )\n' \ 'DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )\n' \
'echo "[Shell Launch Script] Executing from: $DIR"\n' \ 'echo "[Shell Launch Script] Executing from: $DIR"\n' \
'./%s' % os.path.join(exec_folder, "ardublockly") './%s' % os.path.join(exec_folder_name, "ardublockly")
shell_location = os.path.join( shell_location = os.path.join(
project_root_dir, "ardublockly_run.sh") project_root_dir, "ardublockly_run.sh")
else: else:
......
...@@ -10,15 +10,16 @@ ...@@ -10,15 +10,16 @@
'use strict'; 'use strict';
var app = require('app'); var app = require('app');
var dialog = require('dialog');
var winston = require('winston'); var winston = require('winston');
var appMenu = require('./appmenu.js'); var appMenu = require('./appmenu.js');
var server = require('./servermgr.js'); var server = require('./servermgr.js');
var BrowserWindow = require('browser-window'); var BrowserWindow = require('browser-window');
var projectRootLocator = require('./rootlocator.js'); var projectLocator = require('./projectlocator.js');
var env = require('./vendor/electron_boilerplate/env_config'); var env = require('./vendor/electron_boilerplate/env_config');
var windowStateKeeper = require('./vendor/electron_boilerplate/window_state'); var windowStateKeeper = require('./vendor/electron_boilerplate/window_state');
var tag = '[Ardublockly Electron] ';
// Global reference of the window object must be maintain, or the window will // Global reference of the window object must be maintain, or the window will
// be closed automatically when the JavaScript object is garbage collected. // be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null; var mainWindow = null;
...@@ -31,17 +32,20 @@ var mainWindowState = windowStateKeeper('main', { ...@@ -31,17 +32,20 @@ var mainWindowState = windowStateKeeper('main', {
}); });
app.on('ready', function() { app.on('ready', function() {
var projectRootPath = projectRootLocator.getProjectRootPath(); createSplashWindow();
// Setting up logging system // Setting up logging system
var projectRootPath = projectLocator.getProjectRootPath();
winston.add(winston.transports.File, { winston.add(winston.transports.File, {
json: false, json: false,
filename: projectRootPath + '/ardublockly.log', filename: projectRootPath + '/ardublockly.log',
maxsize: 10485760, maxsize: 10485760,
maxFiles: 2 maxFiles: 2
}); });
winston.info(tag + 'Ardublockly root dir: ' + ardublocklyRootDir.cwd());
createSplashWindow(); // Relevant OS could be win32, linux, darwin
winston.info(tag + 'OS detected: ' + process.platform);
server.startServer(); server.startServer();
...@@ -81,7 +85,7 @@ app.on('ready', function() { ...@@ -81,7 +85,7 @@ app.on('ready', function() {
mainWindow.webContents.on('did-fail-load', mainWindow.webContents.on('did-fail-load',
function(event, errorCode, errorDescription) { function(event, errorCode, errorDescription) {
winston.warn('Page failed to load (' + errorCode + '). The ' + winston.warn(tag + 'Page failed to load (' + errorCode + '). The ' +
'server is probably not yet running. Trying again in 200 ms.'); 'server is probably not yet running. Trying again in 200 ms.');
setTimeout(function() { setTimeout(function() {
mainWindow.webContents.reload(); mainWindow.webContents.reload();
...@@ -118,7 +122,7 @@ app.on('window-all-closed', function() { ...@@ -118,7 +122,7 @@ app.on('window-all-closed', function() {
function createSplashWindow() { function createSplashWindow() {
if (splashWindow === null) { if (splashWindow === null) {
var projectJetPath = projectRootLocator.getProjectRootJetpack(); var projectJetPath = projectLocator.getProjectRootJetpack();
var imagePath = 'file://' + projectJetPath.path( var imagePath = 'file://' + projectJetPath.path(
'ardublockly', 'img', 'ardublockly_splash.png'); 'ardublockly', 'img', 'ardublockly_splash.png');
......
...@@ -4,18 +4,36 @@ ...@@ -4,18 +4,36 @@
* @license Licensed under the The MIT License (MIT), a copy can be found in * @license Licensed under the The MIT License (MIT), a copy can be found in
* the electron project directory LICENSE file. * the electron project directory LICENSE file.
* *
* @fileoverview Finds the Ardublockly root directory path. * @fileoverview Finds the Ardublockly Project directory and files.
*/ */
'use strict'; 'use strict';
var winston = require('winston'); var dialog = require('dialog');
var jetpack = require('fs-jetpack'); var jetpack = require('fs-jetpack');
var env = require('./vendor/electron_boilerplate/env_config'); var env = require('./vendor/electron_boilerplate/env_config');
// Name of the folder containing the electron executable, needs to be synced
// with the name set in the Python server and Electron build files.
var execFolderName = 'arduexec';
var serverExecFolderName = 'server';
var serverExecName = 'start';
module.exports.ardublocklyExecFolderName = execFolderName;
var tag = '[Project Root Locator] '; var tag = '[Project Root Locator] ';
var ardublocklyRootDir = null; var ardublocklyRootDir = null;
function ardublocklyNotFound(working_dir) {
dialog.showMessageBox({
type: 'warning',
title: 'Unable to locate Ardublockly folder',
buttons: ['ok'],
message: 'The Ardublockly folder could not be found within the ' +
'execution directory:\n\t' + working_dir + '\nThe ' +
'application will not be able to function properly.'
});
}
module.exports.getProjectRootJetpack = function() { module.exports.getProjectRootJetpack = function() {
if (ardublocklyRootDir === null) { if (ardublocklyRootDir === null) {
// First, work out the project root directory // First, work out the project root directory
...@@ -28,8 +46,6 @@ module.exports.getProjectRootJetpack = function() { ...@@ -28,8 +46,6 @@ module.exports.getProjectRootJetpack = function() {
ardublocklyRootDir = jetpack.dir(__dirname); ardublocklyRootDir = jetpack.dir(__dirname);
var oldArdublocklyRootDir = ''; var oldArdublocklyRootDir = '';
while (ardublocklyRootDir.path() != oldArdublocklyRootDir) { while (ardublocklyRootDir.path() != oldArdublocklyRootDir) {
//winston.log('info', tag + 'Search for Ardublockly project ' +
// 'dir: ' + ardublocklyRootDir.cwd());
// Check if /ardublokly/index.html exists within current path // Check if /ardublokly/index.html exists within current path
if (jetpack.exists( if (jetpack.exists(
ardublocklyRootDir.path('ardublockly', 'index.html'))) { ardublocklyRootDir.path('ardublockly', 'index.html'))) {
...@@ -45,12 +61,37 @@ module.exports.getProjectRootJetpack = function() { ...@@ -45,12 +61,37 @@ module.exports.getProjectRootJetpack = function() {
ardublocklyNotFound(ardublocklyRootDir.path('.')); ardublocklyNotFound(ardublocklyRootDir.path('.'));
} }
} }
winston.info(tag + 'Ardublockly root dir: ' + ardublocklyRootDir.cwd());
} }
return ardublocklyRootDir; return ardublocklyRootDir;
}; };
module.exports.getProjectRootPath = function() { module.exports.getProjectRootPath = function() {
return module.exports.getProjectRootJetpack().path(); return module.exports.getProjectRootJetpack().path();
}; };
module.exports.getExecDirJetpack = function() {
return module.exports.getProjectRootJetpack().cwd(execFolderName);
};
module.exports.getExecDirPath = function() {
return module.exports.getProjectRootJetpack().path(execFolderName);
};
module.exports.getServerExecDirJetpack = function() {
return module.exports.getProjectRootJetpack()
.cwd(execFolderName, serverExecFolderName);
};
module.exports.getServerExecDirPath = function() {
return module.exports.getProjectRootJetpack()
.path(execFolderName, serverExecFolderName);
};
module.exports.getServerExecPath = function() {
var finalServerExecName = serverExecName;
if (process.platform == 'win32') {
finalServerExecName += '.exe';
}
return module.exports.getServerExecDirJetpack().path(finalServerExecName);
};
...@@ -8,56 +8,17 @@ ...@@ -8,56 +8,17 @@
*/ */
'use strict'; 'use strict';
var os = require('os');
var dialog = require('dialog');
var winston = require('winston'); var winston = require('winston');
var jetpack = require('fs-jetpack');
var childProcess = require('child_process'); var childProcess = require('child_process');
var projectRootLocator = require('./rootlocator.js'); var projectLocator = require('./projectlocator.js');
var env = require('./vendor/electron_boilerplate/env_config');
var tag = '[Server mgr] ' var tag = '[Server mgr] '
var serverProcess = null; var serverProcess = null;
function getServerExecLocation() {
// Relevant OS could be win32, linux, darwin
winston.info(tag + 'OS detected: ' + process.platform);
var ardublocklyProjRootDir = projectRootLocator.getProjectRootJetpack();
// Then, work out the location of the python executable files
if (process.platform == 'darwin') {
var arduexecDir = ardublocklyProjRootDir.dir('server');
} else {
var arduexecDir = ardublocklyProjRootDir.dir('arduexec/server');
}
// Finally, work out the name of the executable
var arduexecFileName = 'start';
if (process.platform == 'win32') {
arduexecFileName += '.exe';
}
var executableLocation = arduexecDir.path(arduexecFileName);
winston.info(tag + 'Server executable: ' + executableLocation);
return executableLocation;
}
function ardublocklyNotFound(working_dir) {
dialog.showMessageBox({
type: 'warning',
title: 'Server Error',
buttons: ['ok'],
message: 'The Ardublockly folder could not be found within the ' +
'execution directory:\n' + working_dir + '\nThe application ' +
'will not be able to function properly.'
});
}
module.exports.startServer = function() { module.exports.startServer = function() {
if (serverProcess === null) { if (serverProcess === null) {
var serverExecLocation = getServerExecLocation(); var serverExecLocation = projectLocator.getServerExecPath();
winston.info(tag + 'Command: ' + serverExecLocation + winston.info(tag + 'Command: ' + serverExecLocation +
' --findprojectroot --nobrowser'); ' --findprojectroot --nobrowser');
serverProcess = childProcess.spawn( serverProcess = childProcess.spawn(
......
...@@ -6,20 +6,22 @@ var childProcess = require('child_process'); ...@@ -6,20 +6,22 @@ var childProcess = require('child_process');
var jetpack = require('fs-jetpack'); var jetpack = require('fs-jetpack');
var asar = require('asar'); var asar = require('asar');
var utils = require('./utils'); var utils = require('./utils');
var projectLocator = require('../app/projectlocator.js');
var projectDir; var projectDir;
var releasesDir; var releasesDir;
var packName; var packName;
var packDir; var packDir;
var tmpDir; var tmpDir;
var arduexecDir; var arduExecDir;
var readyAppDir; var readyAppDir;
var manifest; var manifest;
var init = function () { var init = function () {
projectDir = jetpack; projectDir = jetpack;
tmpDir = projectDir.dir('./tmp', { empty: true }); tmpDir = projectDir.dir('./tmp', { empty: true });
arduexecDir = projectDir.dir('../../arduexec'); arduExecDir = projectDir.dir('../../' +
projectLocator.ardublocklyExecFolderName);
releasesDir = projectDir.dir('./releases'); releasesDir = projectDir.dir('./releases');
manifest = projectDir.read('app/package.json', 'json'); manifest = projectDir.read('app/package.json', 'json');
packName = manifest.name + '_' + manifest.version; packName = manifest.name + '_' + manifest.version;
...@@ -108,7 +110,7 @@ var packToDebFile = function () { ...@@ -108,7 +110,7 @@ var packToDebFile = function () {
}; };
var copyExecFolder = function () { var copyExecFolder = function () {
readyAppDir.copy(readyAppDir.cwd(), arduexecDir.cwd(), { overwrite: true }); readyAppDir.copy(readyAppDir.cwd(), arduExecDir.cwd(), { overwrite: true });
return Q(); return Q();
}; };
......
...@@ -122,8 +122,8 @@ var copyExecFolder = function () { ...@@ -122,8 +122,8 @@ var copyExecFolder = function () {
// Because the python build file packs the entire arduexe folder as an app // Because the python build file packs the entire arduexe folder as an app
// package with its respective 'Contents' folder, we want to copy that data // package with its respective 'Contents' folder, we want to copy that data
var finalAppContentDir = finalAppDir.dir('Contents'); var finalAppContentDir = finalAppDir.dir('Contents');
gulpUtil.log('Copying from ' + finalAppDir.cwd() + ' ' + gulpUtil.log('Copying from ' + finalAppDir.path() + ' ' +
'folder: '+ finalAppContentDir.cwd()); 'folder: '+ finalAppContentDir.path());
finalAppDir.copy(finalAppContentDir.cwd(), ardublocklyProjectDir.cwd(), { overwrite: true }); finalAppDir.copy(finalAppContentDir.cwd(), ardublocklyProjectDir.cwd(), { overwrite: true });
return Q(); return Q();
}; };
......
...@@ -6,10 +6,11 @@ var childProcess = require('child_process'); ...@@ -6,10 +6,11 @@ var childProcess = require('child_process');
var jetpack = require('fs-jetpack'); var jetpack = require('fs-jetpack');
var asar = require('asar'); var asar = require('asar');
var utils = require('./utils'); var utils = require('./utils');
var projectLocator = require('../app/projectlocator.js');
var projectDir; var projectDir;
var tmpDir; var tmpDir;
var arduexecDir; var arduExecDir;
var releasesDir; var releasesDir;
var readyAppDir; var readyAppDir;
var manifest; var manifest;
...@@ -17,7 +18,8 @@ var manifest; ...@@ -17,7 +18,8 @@ var manifest;
var init = function () { var init = function () {
projectDir = jetpack; projectDir = jetpack;
tmpDir = projectDir.dir('./tmp', { empty: true }); tmpDir = projectDir.dir('./tmp', { empty: true });
arduexecDir = projectDir.dir('../../arduexec'); arduExecDir = projectDir.dir('../../' +
projectLocator.ardublocklyExecFolderName);
releasesDir = projectDir.dir('./releases'); releasesDir = projectDir.dir('./releases');
manifest = projectDir.read('app/package.json', 'json'); manifest = projectDir.read('app/package.json', 'json');
readyAppDir = tmpDir.cwd(manifest.name); readyAppDir = tmpDir.cwd(manifest.name);
...@@ -120,7 +122,7 @@ var createInstaller = function () { ...@@ -120,7 +122,7 @@ var createInstaller = function () {
}; };
var copyExecFolder = function () { var copyExecFolder = function () {
readyAppDir.copy(readyAppDir.cwd(), arduexecDir.cwd(), { overwrite: true }); readyAppDir.copy(readyAppDir.cwd(), arduExecDir.cwd(), { overwrite: true });
return Q(); return Q();
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment