Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
I have looked for an answer in the various posts but have not found anything, so here is the question.
I am using Arbortext Editor 5.3. We have a couple of script files (init.acl and user.acl) on a network folder, say s:\scripts.
To avoid network latency the script files are copied to a local hard drive and loaded from there when Arbortext is executed. Occasionally one or more of these scripts may change. I want to make it easy for users to check for updates by providing an menu option they can use. The idea is it checks the version of the local script and then checks the version of the network script.
In each script file I put a version that I want to check against later, e.g $initscriptver=1 and $userscriptver=1,
what I want to do in my check_for_updates.acl script is something similar to the following:
I am having trouble working out how to do step 3 (and possibly step 2 ). As I may not be the only one updating the scripts, the version number position may change (e.g. there could be whitespace either side of the "=")
An example of the code is:
function Find_string_in_file(strtofind, from)
{
srcFile = open(from, "r")
if (srcFile < 0)
{
eval "Couldn’t open file for read:", from
return 0
}
while (getline(srcFile, line))
{
$pos=span($line, $strtofind);
if ($pos > 0)
{
#
# extract the version somehow
#
break;
}
}
close(srcFile)
return 1; # True
}
Any pointers would be greatly appreciated.
Solved! Go to Solution.
I thought I would share what I came up with. If there is a better way, please feel free to comment.
Each script file has a variable that defines the version of the script, e.g user.acl has a line:
$UserFileVersion=2.1
I add a menu option in the Help menu to run the script checker:
menu_add .Help.#6 "Check for Script Update" -cmd {Script_Checker::Check_for_Update()}
The checking takes place in a separate package:
package Script_Checker
$MasterFolder="S:/01 Arbortext/scripts/"
# $UserFolder="C:/Program Files (x86)/Arbortext/scripts/"
$DestInitFile=$ENV["APTRCFILE"]
$DestUserFile=$ENV["APTRC"]
$InitFilename="init.acl"
$UserFilename="user.acl"
$UpdateInit=0; # set to 1 if update is needed
$UpdateUser=0
#-------------------------------------------------------
function Find_string_in_file(strtofind, FileToSearch)
#-------------------------------------------------------
# Purpose: Searches for the string in the specified file and returns the line containing the string
# The FileToSearch is the full path and filename.
#
{
local srcFile, line, i, pos
srcFile = open(FileToSearch, "r")
if (srcFile < 0)
{
eval "Couldn’t open file for read:", FileToSearch
return 0
}
$i = 0
while (getline(srcFile, line))
{
$i++
chop(line)
$pos=index(line, strtofind)
if ($pos > 0)
{
close(srcFile)
return "$line"
}
}
close(srcFile)
return 1; # True
}
#-------------------------------------------------------
function Update_Scripts()
#-------------------------------------------------------
{
if ($UpdateInit==1)
{
s='cp "' . $MasterFolder . $InitFilename .'" "' . $DestInitFile . '"'
# message_box(s, 0x00)
execute($s)
}
if ($UpdateUser==1)
{
s='cp "' . $MasterFolder . $UserFilename .'" "' . $DestUserFile . '"'
execute($s)
}
}
#-------------------------------------------------------
function Check_for_Update()
#-------------------------------------------------------
{
local v, f, s
# Check whether init file needs updating
$n=0
$v=0
$f=$MasterFolder . $InitFilename
$s=Find_string_in_file('$InitFileVersion', $f)
if (length($s) > 0)
{
$pos=index(s,'=')
$v=substr(s,$pos+1,2)
# message_box('$v='.$v, 0x00)
if ($v!=$InitFileVersion)
{
$UpdateInit=1
$n++
}
}
# Check whether user file needs updating
$v=0
$f=$MasterFolder . $UserFilename
$s=Find_string_in_file('$UserFileVersion', $f)
if (length($s) > 0)
{
$pos=index(s,'=')
$v=substr(s,$pos+1,2)
if ($v!=$UserFileVersion)
{
$UpdateUser=1
$n++
}
}
if ($n>0)
{
$r=message_box("At least one script requires updating.\n\nWould you like to update the script(s) now?", 0x03+0x20)
switch (r)
{
case 0: #
message "0"
break
case 1: # Yes
message "Updating script(s)..."
Update_Scripts()
message_box("Script(s) Updated. Updated script(s) will be available when you restart Arbortext.",0x00)
message "Ready"
break
case 2:
message "2"; # No
break
case 3:
message "3"; # Cancel
break
}
}
}
You can do it this way but I would recommend to save yourself the hard work and use the built-in Arbortext feature
"zipped customisations". This is documented in the Arbortext Help Center (topic #17122). In your case you can host your custom scripts on a web server and on the client simply set APTCUSTOM=http://my.server.com/arbortext/scripts.zip
Here is an extract:
Thanks for your reply, Gareth. I would love to make my jo simpler but, alas, the organisation I work for has pretty much locked everything down on the local drives and also wrt web servers. I am in a technical publications team and the scripts are for the team. They do not have a wider audience so even if we were able to deploy a webserver it would probably be overkill. We are very much restricted to what we can access on a network drive and essentially one unlocked folder on our local hard drives. So I am somewhat forced to do it the hard way.
Cheers
I think the zipped customisations can work from a regular file share too, as you don't have a web server. Try it out and see? This will avoid you needing to write any code.
I'm not able to use customizations. Is there a way to get a string from a text (script) file?
Thanks
The Arbortext Help Center is a great resource. It is included with Arbortext as an optional download and is also available online: https://support.ptc.com/help/arbortext/r8.1.0.0/en/
Navigate to Programming -> Arbortext Command Language -> Functions by Category -> File Identifier Functions. You will find complete reference materials for open() read() seek() getline() close() etc.
I thought I would share what I came up with. If there is a better way, please feel free to comment.
Each script file has a variable that defines the version of the script, e.g user.acl has a line:
$UserFileVersion=2.1
I add a menu option in the Help menu to run the script checker:
menu_add .Help.#6 "Check for Script Update" -cmd {Script_Checker::Check_for_Update()}
The checking takes place in a separate package:
package Script_Checker
$MasterFolder="S:/01 Arbortext/scripts/"
# $UserFolder="C:/Program Files (x86)/Arbortext/scripts/"
$DestInitFile=$ENV["APTRCFILE"]
$DestUserFile=$ENV["APTRC"]
$InitFilename="init.acl"
$UserFilename="user.acl"
$UpdateInit=0; # set to 1 if update is needed
$UpdateUser=0
#-------------------------------------------------------
function Find_string_in_file(strtofind, FileToSearch)
#-------------------------------------------------------
# Purpose: Searches for the string in the specified file and returns the line containing the string
# The FileToSearch is the full path and filename.
#
{
local srcFile, line, i, pos
srcFile = open(FileToSearch, "r")
if (srcFile < 0)
{
eval "Couldn’t open file for read:", FileToSearch
return 0
}
$i = 0
while (getline(srcFile, line))
{
$i++
chop(line)
$pos=index(line, strtofind)
if ($pos > 0)
{
close(srcFile)
return "$line"
}
}
close(srcFile)
return 1; # True
}
#-------------------------------------------------------
function Update_Scripts()
#-------------------------------------------------------
{
if ($UpdateInit==1)
{
s='cp "' . $MasterFolder . $InitFilename .'" "' . $DestInitFile . '"'
# message_box(s, 0x00)
execute($s)
}
if ($UpdateUser==1)
{
s='cp "' . $MasterFolder . $UserFilename .'" "' . $DestUserFile . '"'
execute($s)
}
}
#-------------------------------------------------------
function Check_for_Update()
#-------------------------------------------------------
{
local v, f, s
# Check whether init file needs updating
$n=0
$v=0
$f=$MasterFolder . $InitFilename
$s=Find_string_in_file('$InitFileVersion', $f)
if (length($s) > 0)
{
$pos=index(s,'=')
$v=substr(s,$pos+1,2)
# message_box('$v='.$v, 0x00)
if ($v!=$InitFileVersion)
{
$UpdateInit=1
$n++
}
}
# Check whether user file needs updating
$v=0
$f=$MasterFolder . $UserFilename
$s=Find_string_in_file('$UserFileVersion', $f)
if (length($s) > 0)
{
$pos=index(s,'=')
$v=substr(s,$pos+1,2)
if ($v!=$UserFileVersion)
{
$UpdateUser=1
$n++
}
}
if ($n>0)
{
$r=message_box("At least one script requires updating.\n\nWould you like to update the script(s) now?", 0x03+0x20)
switch (r)
{
case 0: #
message "0"
break
case 1: # Yes
message "Updating script(s)..."
Update_Scripts()
message_box("Script(s) Updated. Updated script(s) will be available when you restart Arbortext.",0x00)
message "Ready"
break
case 2:
message "2"; # No
break
case 3:
message "3"; # Cancel
break
}
}
}