Added simple console wizard for Eiffel Studio.

(It is not very user friendly, this is a first draft)
It should be improved in the future (with GUI, ...)
This commit is contained in:
Jocelyn Fiat
2012-06-22 15:54:50 +02:00
parent 87c2074d2b
commit 9b13aa27dd
14 changed files with 843 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
class
EWF_WIZARD
inherit
WIZARD
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
initialize
get_information
if is_valid and attached layout as lay then
generate_project (lay)
end
end
feature -- Status
feature -- Access
project_directory_name: detachable READABLE_STRING_8
projet_name: detachable READABLE_STRING_8
use_router: BOOLEAN
router_type: detachable READABLE_STRING_8
connector: detachable READABLE_STRING_8
feature -- Form
get_information
local
e: EXECUTION_ENVIRONMENT
do
create e
project_directory_name := e.get ("ISE_PROJECTS")
if
attached project_directory_name as pdn and then
attached string_question ("Project directory (default=" + pdn + ")? ", <<["q", Void]>>, pdn, False) as r_pdn
then
project_directory_name := r_pdn.string
elseif attached string_question ("Project directory ? ", <<["q", Void]>>, Void, False) as r_pdn then
project_directory_name := r_pdn.string
end
if project_directory_name = Void then
die (-1)
end
if attached string_question ("Project name ? ", Void, Void, False) as pn then
projet_name := pn.string
else
projet_name := "ewf"
end
if boolean_question ("Do you want to use router (Y|n) ? ", <<["y", True], ["Y", True]>>, "Y") then
use_router := True
router_type := "uri-template"
else
use_router := False
end
if attached string_question ("[
Default connector ?
1 - Eiffel Web Nino (standalone web server)
2 - CGI application (requires to setup httpd server)
3 - libFCGI application (requires to setup httpd server)
Your choice:
]", <<["1", "nino"], ["2", "cgi"], ["3", "libfcgi"]>>, "1", True) as conn
then
connector := conn
else
connector := "nino"
end
end
is_valid: BOOLEAN
do
Result := project_directory_name /= Void and projet_name /= Void
end
generate_project (a_layout: WIZARD_LAYOUT)
require
is_valid
local
d: DIRECTORY
dn: DIRECTORY_NAME
tfn: FILE_NAME
res: WIZARD_SUCCEED_RESPONSE
do
if attached project_directory_name as pdn then
if attached projet_name as pn then
variables.force (pn, "TARGET_NAME")
variables.force (new_uuid, "UUID")
variables.force ("none", "CONCURRENCY")
if attached connector as conn then
variables.force (conn, "EWF_CONNECTOR")
end
variables.force ("9999", "EWF_NINO_PORT")
create dn.make_from_string (pdn)
dn.extend (pn)
create d.make (dn.string)
if not d.exists then
d.recursive_create_dir
end
create tfn.make_from_string (dn.string)
tfn.set_file_name (pn)
tfn.add_extension ("ecf")
copy_resource_template ("template.ecf", tfn.string)
create res.make (tfn.string, d.name)
create dn.make_from_string (pdn)
dn.extend (pn)
dn.extend ("src")
create d.make (dn.string)
if not d.exists then
d.recursive_create_dir
end
create tfn.make_from_string (dn.string)
tfn.set_file_name ("ewb_application")
tfn.add_extension ("e")
if attached router_type as rt then
check rt.same_string ("uri-template") end
copy_resource_template ("ewb_application-"+ rt +".e", tfn.string)
else
copy_resource_template ("ewb_application.e", tfn.string)
end
create tfn.make_from_string (dn.string)
tfn.set_file_name ("ewf")
tfn.add_extension ("ini")
copy_resource_template ("ewf.ini", tfn.string)
send_response (res)
end
end
end
feature -- Output
feature {NONE} -- Implementation
invariant
-- invariant_clause: True
end

View File

@@ -0,0 +1,265 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
deferred class
WIZARD
inherit
ARGUMENTS
feature {NONE} -- Initialization
initialize
-- Initialize `Current'.
local
i,n: INTEGER
s: READABLE_STRING_8
wizard_directory_name: detachable READABLE_STRING_8
callback_file_name: detachable READABLE_STRING_8
do
create variables.make (5)
n := argument_count
if n > 0 then
from
i := 1
until
i > n
loop
s := argument (i)
if s.same_string ("-callback") or s.same_string ("--callback") then
i := i + 1
if i <= n then
callback_file_name := argument (i)
end
elseif wizard_directory_name = Void then
wizard_directory_name := s
else
debug
io.error.put_string ("Ignoring argument %"" + s + "%"%N")
end
end
i := i + 1
end
end
if wizard_directory_name = Void then
display_usage (io.error)
quit ("ERROR: Missing wizard directory name.")
elseif callback_file_name = Void then
display_usage (io.error)
quit ("ERROR: Missing Eiffel Studio callback file name.")
else
create layout.make (wizard_directory_name, callback_file_name)
end
end
feature -- Status
display_usage (f: FILE)
do
f.put_string ("Usage: wizard {dirname} -callback {filename}%N")
f.put_string (" -callback filename: file used to communicate back with Eiffel Studio%N")
f.put_string (" dirname: folder containing the wizard resources, pixmaps, ...%N")
end
quit (m: detachable READABLE_STRING_8)
do
if m /= Void then
io.error.put_string (m)
end
send_response (create {WIZARD_FAILED_RESPONSE})
ensure
False -- never reached
end
die (code: INTEGER)
do
(create {EXCEPTIONS}).die (code)
end
feature -- Access
variables: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
layout: detachable WIZARD_LAYOUT
feature -- Response
send_response (res: WIZARD_RESPONSE)
local
f: RAW_FILE
do
if attached layout as lay then
create f.make (lay.callback_file_name)
if not f.exists or else f.is_writable then
f.open_write
res.send (f)
f.close
else
die (0)
end
else
die (0)
end
end
feature {NONE} -- Implementation
boolean_question (m: READABLE_STRING_8; a_options: detachable ITERABLE [TUPLE [key: READABLE_STRING_8; value: BOOLEAN]]; def: detachable STRING_8): BOOLEAN
local
s: STRING_8
l_answered: BOOLEAN
l_options: detachable ITERABLE [TUPLE [key: READABLE_STRING_8; value: BOOLEAN]]
do
from
until
l_answered
loop
io.put_string (m)
if l_options = Void then
l_options := a_options
end
if l_options = Void then
l_options := <<["y", True], ["Y", True]>>
end
io.read_line
s := io.last_string
s.left_adjust
s.right_adjust
if s.is_empty and def /= Void then
s := def
end
if not s.is_empty then
across
l_options as o
until
l_answered
loop
if o.item.key.same_string (s) then
l_answered := True
Result := o.item.value
end
end
if not l_answered then
l_answered := True
Result := False
end
end
end
end
string_question (m: READABLE_STRING_8; a_options: detachable ITERABLE [TUPLE [key: READABLE_STRING_8; value: detachable READABLE_STRING_8]]; def: detachable READABLE_STRING_8; a_required_valid_option: BOOLEAN): detachable READABLE_STRING_8
local
s: STRING_8
l_answered: BOOLEAN
do
from
until
l_answered
loop
io.put_string (m)
io.read_line
s := io.last_string
s.left_adjust
s.right_adjust
if s.is_empty and def /= Void then
s := def
end
if not s.is_empty then
if a_options /= Void then
across
a_options as o
until
l_answered
loop
if o.item.key.same_string (s) then
l_answered := True
Result := o.item.value
end
end
end
if not l_answered then
l_answered := True
Result := s
if
a_required_valid_option and then
a_options /= Void and then
not across a_options as o some attached o.item.value as v and then Result.same_string (v) end
then
l_answered := False
Result := Void
end
end
end
end
end
copy_file (a_src, a_target: READABLE_STRING_8)
local
f,t: RAW_FILE
do
create f.make (a_src)
if f.exists and f.is_readable then
create t.make (a_target)
if not t.exists or else t.is_writable then
f.open_read
t.open_write
f.copy_to (t)
t.close
f.close
end
end
end
new_uuid: STRING_8
local
gen: UUID_GENERATOR
do
create gen
Result := gen.generate_uuid.out
end
feature -- Resources
copy_resource (a_res: READABLE_STRING_8; a_target: READABLE_STRING_8)
do
if attached layout as lay then
copy_file (lay.resource (a_res), a_target)
end
end
copy_resource_template (a_res: READABLE_STRING_8; a_target: READABLE_STRING_8)
local
f,t: RAW_FILE
do
if attached layout as lay then
create f.make (lay.resource (a_res))
if f.exists and f.is_readable then
create t.make (a_target)
if not t.exists or else t.is_writable then
f.open_read
t.create_read_write
from
f.read_line
until
f.exhausted
loop
across
variables as v
loop
f.last_string.replace_substring_all ("${WIZ:" + v.key + "}", v.item)
end
t.put_string (f.last_string)
t.put_new_line
f.read_line
end
t.close
f.close
end
end
end
end
end

View File

@@ -0,0 +1,20 @@
note
description: "Summary description for {WIZARD_FAILED_RESPONSE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WIZARD_FAILED_RESPONSE
inherit
WIZARD_RESPONSE
feature -- Output
send (f: FILE)
do
f.put_string ("Success=%"no%"%N")
end
end

View File

@@ -0,0 +1,49 @@
note
description: "Summary description for {WIZARD_LAYOUT}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WIZARD_LAYOUT
create
make
feature {NONE} -- Initialization
make (d: like wizard_directory_name; cb: like callback_file_name)
do
wizard_directory_name := d
callback_file_name := cb
end
feature -- Access
wizard_directory_name: READABLE_STRING_8
resource (a_name: READABLE_STRING_8): STRING_8
local
fn: FILE_NAME
do
create fn.make_from_string (wizard_directory_name)
fn.extend ("resources")
fn.set_file_name (a_name)
Result := fn.string
end
pixmap_png_filename (a_name: READABLE_STRING_8): STRING_8
local
fn: FILE_NAME
do
create fn.make_from_string (wizard_directory_name)
fn.extend ("pixmaps")
fn.set_file_name (a_name)
fn.add_extension ("png")
Result := fn.string
end
callback_file_name: READABLE_STRING_8
invariant
end

View File

@@ -0,0 +1,16 @@
note
description: "Summary description for {WIZARD_RESPONSE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WIZARD_RESPONSE
feature -- Output
send (f: FILE)
deferred
end
end

View File

@@ -0,0 +1,68 @@
note
description: "Summary description for {WIZARD_SUCCEED_RESPONSE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WIZARD_SUCCEED_RESPONSE
inherit
WIZARD_RESPONSE
create
make
feature {NONE} -- Initialization
make (a_conf_fn: like configuration_file_name; a_dir: like directory_name)
do
configuration_file_name := a_conf_fn
directory_name := a_dir
end
feature -- Access
configuration_file_name: READABLE_STRING_8
directory_name: READABLE_STRING_8
compile_enabled: BOOLEAN
freeze_required: BOOLEAN
feature -- Element Change
set_compile_enabled (b: BOOLEAN)
do
compile_enabled := b
end
set_freeze_required (b: BOOLEAN)
do
freeze_required := b
end
feature -- Constants
melt_compilation: INTEGER = 0
freeze_compilation: INTEGER = 1
feature -- Output
send (f: FILE)
do
f.put_string ("Success=%"yes%"%N")
f.put_string ("Ace=%"" + configuration_file_name + "%"%N")
f.put_string ("Directory=%"" + directory_name + "%"%N")
if compile_enabled then
f.put_string ("Compilation=%"yes%"%N")
else
f.put_string ("Compilation=%"no%"%N")
end
if freeze_required then
f.put_string ("Compilation_type=%"freeze%"%N")
elseif compile_enabled then
f.put_string ("Compilation_type=%"melt%"%N")
end
end
end