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/
####################
# Project specific #
####################
# Arduino sketch generated by the application
# Arduino sketch generated by the Python server
ArdublocklySketch.ino
# Server App settinsg file generated
# Server App settings file generated by the Python server
ServerCompilerSettings.ini
# Desktop application log file
......@@ -81,11 +81,6 @@ ardublockly2.log
# Anything starting with this is created as a unit/module testing temporal file
TestTemp_*
# CEF cache and log files
webcache
cef_error.log
cef_debug.log
# Miscellaneous files that should not get revisioned
/ignore
......@@ -94,8 +89,6 @@ cef_debug.log
/upload
/releases
/arduexec
/arduexec.app
ardublockly_server_run.*
ardublockly_run.*
# The documentation is built with the GitHub wiki data
......
......@@ -28,8 +28,8 @@ Ardublockly.isRunningElectron = function() {
*/
Ardublockly.loadJsInElectron = function() {
if (Ardublockly.isRunningElectron()) {
var projectRootLocator = require('remote').require('./rootlocator.js');
var projectRoot = projectRootLocator.getProjectRootPath();
var projectLocator = require('remote').require('./projectlocator.js');
var projectRoot = projectLocator.getProjectRootPath();
window.$ = window.jQuery = require(projectRoot +
'/ardublockly/js_libs/jquery-2.1.3.min.js');
window.Hammer = require(projectRoot + '/ardublockly/js_libs/hammer.min.js');
......
......@@ -31,7 +31,8 @@ except ImportError:
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_tab = " "
......@@ -40,7 +41,8 @@ script_tab = " "
project_root_dir = \
os.path.dirname( # going up 1 level
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
sys.path.append(project_root_dir)
......@@ -116,7 +118,7 @@ def get_py2exe_options():
# Py2exe options: http://www.py2exe.org/index.cgi/ListOfOptions
py2exe_options = {
"py2exe": {"dist_dir": executable_dir,
"py2exe": {"dist_dir": server_exec_dir,
"compressed": False,
"bundle_files": 3,
"skip_archive": True,
......@@ -152,7 +154,7 @@ def create_run_batch_file():
entry point built by Electron.
"""
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")
try:
batch_file = open(batch_location, "w")
......@@ -174,7 +176,7 @@ def main():
remove_directory(os.path.join(os.getcwd(), "build"))
print(script_tag + "Removing old executable directory.")
remove_directory(executable_dir)
remove_directory(server_exec_dir)
print(script_tag + "Building Ardublockly using py2exe.")
if len(sys.argv) <= 1:
......
......@@ -38,15 +38,8 @@ from glob import glob
spec_coll_name = "server"
if platform.system() == "Darwin":
# On MacOS the Electron app contents are dumped into the project root
# 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")
exec_folder_name = "arduexec"
py_exec_folder = os.path.join(exec_folder_name, spec_coll_name)
script_tag = "[Ardublockly build] "
script_tab = " "
......@@ -56,7 +49,6 @@ project_root_dir = \
os.path.dirname( # going up 1 level
os.path.dirname(os.path.realpath(__file__))) # folder dir of this
# verbose_print = print if verbose else lambda *a, **k: None
......@@ -176,7 +168,7 @@ def create_shell_file(os_type):
shell_text = '#!/bin/bash\n' \
'DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )\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(
project_root_dir, "ardublockly_run.sh")
else:
......
......@@ -10,15 +10,16 @@
'use strict';
var app = require('app');
var dialog = require('dialog');
var winston = require('winston');
var appMenu = require('./appmenu.js');
var server = require('./servermgr.js');
var BrowserWindow = require('browser-window');
var projectRootLocator = require('./rootlocator.js');
var projectLocator = require('./projectlocator.js');
var env = require('./vendor/electron_boilerplate/env_config');
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
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
......@@ -31,17 +32,20 @@ var mainWindowState = windowStateKeeper('main', {
});
app.on('ready', function() {
var projectRootPath = projectRootLocator.getProjectRootPath();
createSplashWindow();
// Setting up logging system
var projectRootPath = projectLocator.getProjectRootPath();
winston.add(winston.transports.File, {
json: false,
filename: projectRootPath + '/ardublockly.log',
maxsize: 10485760,
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();
......@@ -81,7 +85,7 @@ app.on('ready', function() {
mainWindow.webContents.on('did-fail-load',
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.');
setTimeout(function() {
mainWindow.webContents.reload();
......@@ -118,7 +122,7 @@ app.on('window-all-closed', function() {
function createSplashWindow() {
if (splashWindow === null) {
var projectJetPath = projectRootLocator.getProjectRootJetpack();
var projectJetPath = projectLocator.getProjectRootJetpack();
var imagePath = 'file://' + projectJetPath.path(
'ardublockly', 'img', 'ardublockly_splash.png');
......
......@@ -4,18 +4,36 @@
* @license Licensed under the The MIT License (MIT), a copy can be found in
* the electron project directory LICENSE file.
*
* @fileoverview Finds the Ardublockly root directory path.
* @fileoverview Finds the Ardublockly Project directory and files.
*/
'use strict';
var winston = require('winston');
var dialog = require('dialog');
var jetpack = require('fs-jetpack');
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 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() {
if (ardublocklyRootDir === null) {
// First, work out the project root directory
......@@ -28,8 +46,6 @@ module.exports.getProjectRootJetpack = function() {
ardublocklyRootDir = jetpack.dir(__dirname);
var 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
if (jetpack.exists(
ardublocklyRootDir.path('ardublockly', 'index.html'))) {
......@@ -45,12 +61,37 @@ module.exports.getProjectRootJetpack = function() {
ardublocklyNotFound(ardublocklyRootDir.path('.'));
}
}
winston.info(tag + 'Ardublockly root dir: ' + ardublocklyRootDir.cwd());
}
}
return ardublocklyRootDir;
};
module.exports.getProjectRootPath = function() {
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 @@
*/
'use strict';
var os = require('os');
var dialog = require('dialog');
var winston = require('winston');
var jetpack = require('fs-jetpack');
var childProcess = require('child_process');
var projectRootLocator = require('./rootlocator.js');
var env = require('./vendor/electron_boilerplate/env_config');
var projectLocator = require('./projectlocator.js');
var tag = '[Server mgr] '
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() {
if (serverProcess === null) {
var serverExecLocation = getServerExecLocation();
var serverExecLocation = projectLocator.getServerExecPath();
winston.info(tag + 'Command: ' + serverExecLocation +
' --findprojectroot --nobrowser');
serverProcess = childProcess.spawn(
......
......@@ -6,20 +6,22 @@ var childProcess = require('child_process');
var jetpack = require('fs-jetpack');
var asar = require('asar');
var utils = require('./utils');
var projectLocator = require('../app/projectlocator.js');
var projectDir;
var releasesDir;
var packName;
var packDir;
var tmpDir;
var arduexecDir;
var arduExecDir;
var readyAppDir;
var manifest;
var init = function () {
projectDir = jetpack;
tmpDir = projectDir.dir('./tmp', { empty: true });
arduexecDir = projectDir.dir('../../arduexec');
arduExecDir = projectDir.dir('../../' +
projectLocator.ardublocklyExecFolderName);
releasesDir = projectDir.dir('./releases');
manifest = projectDir.read('app/package.json', 'json');
packName = manifest.name + '_' + manifest.version;
......@@ -108,7 +110,7 @@ var packToDebFile = function () {
};
var copyExecFolder = function () {
readyAppDir.copy(readyAppDir.cwd(), arduexecDir.cwd(), { overwrite: true });
readyAppDir.copy(readyAppDir.cwd(), arduExecDir.cwd(), { overwrite: true });
return Q();
};
......
......@@ -122,8 +122,8 @@ var copyExecFolder = function () {
// 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
var finalAppContentDir = finalAppDir.dir('Contents');
gulpUtil.log('Copying from ' + finalAppDir.cwd() + ' ' +
'folder: '+ finalAppContentDir.cwd());
gulpUtil.log('Copying from ' + finalAppDir.path() + ' ' +
'folder: '+ finalAppContentDir.path());
finalAppDir.copy(finalAppContentDir.cwd(), ardublocklyProjectDir.cwd(), { overwrite: true });
return Q();
};
......
......@@ -6,10 +6,11 @@ var childProcess = require('child_process');
var jetpack = require('fs-jetpack');
var asar = require('asar');
var utils = require('./utils');
var projectLocator = require('../app/projectlocator.js');
var projectDir;
var tmpDir;
var arduexecDir;
var arduExecDir;
var releasesDir;
var readyAppDir;
var manifest;
......@@ -17,7 +18,8 @@ var manifest;
var init = function () {
projectDir = jetpack;
tmpDir = projectDir.dir('./tmp', { empty: true });
arduexecDir = projectDir.dir('../../arduexec');
arduExecDir = projectDir.dir('../../' +
projectLocator.ardublocklyExecFolderName);
releasesDir = projectDir.dir('./releases');
manifest = projectDir.read('app/package.json', 'json');
readyAppDir = tmpDir.cwd(manifest.name);
......@@ -120,7 +122,7 @@ var createInstaller = function () {
};
var copyExecFolder = function () {
readyAppDir.copy(readyAppDir.cwd(), arduexecDir.cwd(), { overwrite: true });
readyAppDir.copy(readyAppDir.cwd(), arduExecDir.cwd(), { overwrite: true });
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