CanAce can now run from any location

5 views
Skip to first unread message

Lawrence Woodman

unread,
Feb 24, 2013, 2:24:47 AM2/24/13
to canac...@googlegroups.com
Hello,

I have been working on getting CanAce to the point where it can be installed anywhere and will find the files that it needs.  The latest commit is at:
    https://github.com/LawrenceWoodman/CanAce/commit/c13515135345daf50bc8f6e4c3ddc4d6bcd01443

To do this I have compiled in the canace.tcl file using a method I have described here:
    http://techtinkering.com/2013/02/20/compiling-a-tcl-script-into-an-executable

I have also made use of the XDG base directory specification to locate the ROM image.  A big thanks to Marcos for letting me know about this as I had never heard of it until you had mentioned this standard.  To make use of this I have created a Tcl module called xdgbasedir available from:
    https://github.com/LawrenceWoodman/xdgbasedir_tcl

Unfortunately this has made CanAce a little more tricky to install and I'm currently looking at how to simplify this.  For the moment though, you will need to download xdgbasedir from:
    https://github.com/LawrenceWoodman/xdgbasedir_tcl/tags

And then, as described in its README, copy the module to a directory where Tcl would expect to find modules.  To simplify this I have created the script featured near the end of this email, which when run as root from the base directory of the xdgbasedir_tcl repo, as follows, will install the module into a sensible location automatically:
    $ tclsh installmodule.tcl xdgbasedir*.tm

You will need to copy and past the following script to a file called: installmodule.tcl, in the root of the xdgbasedir repo.

#!/usr/bin/env tclsh
# Simple Tcl module install script
# Usage: installmodule <moduleFilename>
#
# Copyright (C) 2013 Lawrence Woodman
#
# Licensed under an MIT licence.  Please see LICENCE.md for details.
#
# The script will search the module path for a location where modules are
# already installed and try to pick the best location to install the module
# specified.  It must be run by a user that has permission to write to the
# directory.
#

# Get a list of directories in the module search path that are being used
proc getUsedModuleDirs {} {
  set usedModuleDirs {}
  set moduleDirs [split [::tcl::tm::path list]]
  foreach moduleDir $moduleDirs {
    set moduleNames [glob -nocomplain -directory $moduleDir/ *.tm]
    if {[llength $moduleNames] >= 1} {
      lappend usedModuleDirs $moduleDir/
    }
  }
  return $usedModuleDirs
}

# Get the best directory to put the module in
proc getBestModuleDir {moduleDirs} {
  set moduleDirs [getUsedModuleDirs]
  if {[llength $moduleDirs] == 0} {
    puts "Error: Couldn't find any suitable directories for the module"
    exit
  }
  return [lindex $moduleDirs end]
}

# Copy moduleFilename to the most suitable module location
proc installModule {moduleFilename} {
  set destModuleDir [getBestModuleDir [getUsedModuleDirs]]
  if {[catch {file copy -force $moduleFilename $destModuleDir} copyError]} {
     puts "Error: $copyError"
     exit
  }
  puts "Copied $moduleFilename to $destModuleDir"

}

# Outputs a usage suggestion if a single module in current directory
proc makeUsageSuggestion {} {
  set possibleModuleNames [glob -nocomplain *-*.*.tm]
  if {[llength $possibleModuleNames] == 1} {
    puts "Suggestion: installmodule [lindex $possibleModuleNames 0]"
  }
}

proc usageError {msg} {
  puts "Error: $msg"
  puts "Usage: installmodule <moduleFilename>"
  makeUsageSuggestion
  exit
}

if {$argc != 1} {
  usageError "wrong number of arguments"
}

set moduleFilename [lindex $argv 0]
set moduleFilenameRegexp {([[:alpha:]][:[:alnum:]]*)-([[:digit:]].*)\.tm}
if {![regexp $moduleFilenameRegexp $moduleFilename]} {
  usageError "$moduleFilename isn't a valid name for a module"
}

installModule $moduleFilename
# End of File


Let me know how you get on and if there are any problems.


Lorry



-- 
vLife Systems Ltd
Registered Office: The Meridian, 4 Copthall House, Station Square, Coventry, CV1 2FL
Registered in England and Wales No. 06477649
http://vlifesystems.com

Marcos Cruz

unread,
Jul 15, 2013, 12:25:20 PM7/15/13
to CanAce development group, canac...@googlegroups.com

Hello,

These months I've been busy with other things (mainly converting the
Raspberry Pi into a portable computer... Not finished yet).

I've just tried the latest Canace in the Pi with Raspbian.

I downloaded the latest commit; I installed xdgbasedir_tcl with
installmodule_tcl, following the instructions; I compiled the sources
and installed the binary with the usual commands. Everything worked
fine, no error. The binary is in </usr/local/bin/> and the ROM file in
</usr/local/share/canace/>.

But I get this error when I invoque the binary:

Error in embedded canace.tcl
Error: Couldn't load the ACE ROM

A link didn't help:

ln -s /usr/local/share/canace/ace.rom /usr/local/bin/

Maybe I missed something? I haven't investigated further yet.

Marcos

--
http://programandala.net

Lawrence Woodman

unread,
Jul 25, 2013, 1:51:09 AM7/25/13
to canac...@googlegroups.com
On 15/07/13 17:25, Marcos Cruz wrote:
> I downloaded the latest commit; I installed xdgbasedir_tcl with
> installmodule_tcl, following the instructions; I compiled the sources
> and installed the binary with the usual commands. Everything worked
> fine, no error. The binary is in </usr/local/bin/> and the ROM file in
> </usr/local/share/canace/>.
>
> But I get this error when I invoque the binary:
>
> Error in embedded canace.tcl
> Error: Couldn't load the ACE ROM
>
> A link didn't help:
>
> ln -s /usr/local/share/canace/ace.rom /usr/local/bin/
>
> Maybe I missed something? I haven't investigated further yet.

Sorry for the slow response; I have been away.

I'm not sure what the problem is, could you try the following as the user
that you wish to run canace as, and report the results:

$ set | grep XDG


Thanks

Marcos Cruz

unread,
Jul 25, 2013, 11:38:49 AM7/25/13
to CanAce development group
En/Je/On 2013-07-25 06:51, Lawrence Woodman escribi� / skribis / wrote :

> $ set | grep XDG

Thanks. I didn't thought that.

XDG_CACHE_HOME=/home/myuser/.cache
XDG_CONFIG_HOME=/home/myuser/.config
XDG_DATA_HOME=/home/myuser/.local/share
XDG_SESSION_COOKIE=c76f6c7332c486d041b6528b51a0ef02(...)

In fact, I have a doubt: The ROM is installed in
</usr/local/share/canace/>. What does Canace use the XDG directories
for? For example, no <~/.config/canace/> is created.

Anyway I'll try again from the start. Maybe I missed something.

Thank you.

Marcos

--
http://programandala.net

Lawrence Woodman

unread,
Aug 4, 2013, 1:56:55 AM8/4/13
to canac...@googlegroups.com
On 25/07/13 16:38, Marcos Cruz wrote:
> En/Je/On 2013-07-25 06:51, Lawrence Woodman escribi� / skribis / wrote :
>
>> $ set | grep XDG
> Thanks. I didn't thought that.
>
> XDG_CACHE_HOME=/home/myuser/.cache
> XDG_CONFIG_HOME=/home/myuser/.config
> XDG_DATA_HOME=/home/myuser/.local/share
> XDG_SESSION_COOKIE=c76f6c7332c486d041b6528b51a0ef02(...)
>
> In fact, I have a doubt: The ROM is installed in
> </usr/local/share/canace/>. What does Canace use the XDG directories
> for? For example, no <~/.config/canace/> is created.

canace only uses the XDG directories at the moment to locate the ace
ROM, in the future
I intend to use if for the configuration.

I'm a little stumped to be honest with this problem. Could you try
altering the following file:
src/canace.tcl

and search for:
proc ROMLocation

Then directly under:
foreach dir $searchDirs {

Could you insert:
puts "Searching for ROM in: $dir"


Then go to the root of the repository and run:

$ make
$ src/canace

Finally this should print out a list of directories to the console.
Could you let me know
what the output is.

Marcos Cruz

unread,
Aug 4, 2013, 7:29:17 AM8/4/13
to CanAce development group
En/Je/On 2013-08-04 06:56, Lawrence Woodman escribi� / skribis / wrote :

> altering the following file:
> src/canace.tcl
>
> and search for:
> proc ROMLocation
>
> Then directly under:
> foreach dir $searchDirs {
>
> Could you insert:
> puts "Searching for ROM in: $dir"

Thank you. The output is:

Searching for ROM in: /home/myuser/.local/share/canace
Searching for ROM in: usr/local/share/canace
Searching for ROM in: usr/share/canace
Error in embedded canace.tcl
Error: Couldn't load the ACE ROM

The ROM file is right installed, <usr/local/share/canace/ace.rom> with
permissions 644.

Look, there's no slash at the start of the second and third
directories... It seems both <usr/...> paths are relative and that's
why they are not found.

I've copied the ROM to </home/myuser/.local/share/canace/> and it works!

Marcos

--
http://programandala.net

Lawrence Woodman

unread,
Aug 11, 2013, 2:14:20 AM8/11/13
to canac...@googlegroups.com
On 04/08/13 12:29, Marcos Cruz wrote:
Searching for ROM in: /home/myuser/.local/share/canace
Searching for ROM in: usr/local/share/canace
Searching for ROM in: usr/share/canace
Error in embedded canace.tcl
Error: Couldn't load the ACE ROM

The ROM file is right installed, <usr/local/share/canace/ace.rom> with
permissions 644.

Look, there's no slash at the start of the second and third
directories...  It seems both <usr/...> paths are relative and that's
why they are not found.

I've copied the ROM to </home/myuser/.local/share/canace/> and it works!

I'm glad that you got it working, and I have also corrected the
file paths so that they are absolute.  If you download and install
the latest version of the module xdgbasedir from:
  https://github.com/LawrenceWoodman/xdgbasedir_tcl/releases/tag/v0.3

You should find that you can use the system wide locations for the ACE
ROM.

Best wishes

Marcos Cruz

unread,
Aug 11, 2013, 11:34:57 AM8/11/13
to CanAce development group
En/Je/On 2013-08-11 07:14, Lawrence Woodman escribi� / skribis / wrote :

> the latest version of the module xdgbasedir from:
>
> [1]https://github.com/LawrenceWoodman/xdgbasedir_tcl/releases/tag/v0.3
>
> You should find that you can use the system wide locations for the ACE
> ROM.

Thanks. Now it finds the ROM in any directory.

Marcos

--
http://programandala.net
Reply all
Reply to author
Forward
0 new messages