cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Is there a way to search for a string in an ACL file?

MB_8500855
7-Bedrock

Is there a way to search for a string in an ACL file?

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:

  1. Open the network script file (e.g. s:\scripts\init.acl)
  2. Find the line containing the version number (e.g. $initscriptver=1)
  3. Extract the version number from the line
  4. Compare the version number I extracted with the one in the loaded script

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.

ACCEPTED SOLUTION

Accepted Solutions

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
			
		}
	}
}

 

View solution in original post

6 REPLIES 6

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:

You can deploy not only custom directories, but also application and content management system adapters directories in a compressed zip file. Using a zip file to distribute your customizations has the following advantages:
  • You can host your customizations on a web server.
    In this case, use the HTTP or HTTPS URL to the zip file as the value for the APTCUSTOM environment variable.
  • Your customizations will be available to users when they cannot access your network.
    If you use a shared network folder to host your customizations, users do not have access to those customizations when the network is unavailable. If you use a zip file to distribute your customizations, Arbortext Editor unzips those customizations to a directory in the Arbortext Editor cache directory (.aptcache\zc). At start up, Arbortext Editor checks to see whether the zip file has been updated. If it has, Arbortext Editor downloads and uncompresses the updated customizations. If not, Arbortext Editor continues to use the customizations stored in the local cache. If the network is unavailable to a user, your customizations are still available to that user in the local cache. Note that the user must also have a fixed Arbortext Editor license on their system to work away from the network.
  • Network traffic might be reduced.
    Since the zip file containing your customizations is only downloaded once over the network, and then only if it has been updated, traffic on your network might be reduced. If you store your unzipped customizations in a shared network folder, Arbortext Editor might have to access that folder several times over the course of a session.
  • Customizations stored in a compressed zip file are harder to change accidentally than customizations stored in a directory structure.

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
			
		}
	}
}

 

Announcements

Top Tags