Tags:
create new tag
view all tags

Question

Hi, Is there a way for TWiki to read a parameter from a (text) file ?

As an example, let us say that a text file (uploaded on to the TWiki server) contains this text:

apples = good
oranges = rotten
No. of apples = 100
No. of oranges = 25

Is there a way to read the file and find out (and display) the condition of apples/oranges (good / rotten) and the quantity of each (100 / 25) ?

Environment

TWiki version: TWikiRelease04x01x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Windows 2003
Web server: Apache 1.3.39
Perl version: 5.008008 (cygwin)
Client OS: Windows XP
Web Browser: IE 6
Categories: Missing functionality

-- ChengappaCB - 15 Feb 2008

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

How flexible are you on the syntax of the text file, and the variable names? Because one solution would be to define them as TWikiVariables in the file, like this:

  • Set APPLES = good
  • Set ORANGES = rotten
  • Set NUM_APPLES = 100
  • Set NUM_ORANGES = 25

(By convention the variables are upper case, but I don't think that's a requirement)

Then INCLUDE that file. See INCLUDE_page_include_other_topic for details.

Then to display a value, just use the form of %NUM_APPLES% / %NUM_ORANGES%

View the raw form of this page, and you see it works (tho' I didn't use an include here): 100 / 25

-- SeanCMorgan - 19 Feb 2008

In my requirement, the text file comes from another source (a log file) and has a different syntax. But I thibk your idea is good Sean. I will try to tweak something and see if I can use this idea. Thanks a lot smile

-- ChengappaCB - 20 Feb 2008

It looks like this doesn't work with INCLUDE but works only if the variables are set in the same page where it is referenced.

-- ChengappaCB - 24 Feb 2008

It looks like there's a plugin to make that work: TWiki:Plugins.TopicVarsPlugin

Otherwise it looks like you need to use the spreadsheet plugin, using: %CALC{$SET(myvar, blah)}% and %CALC{$GET(myvar, blah)}%. Sorry about that.

-- SeanCMorgan - 03 Mar 2008

If you do not have a need to edit those files in TWiki you could dump .txt files into a TWiki web directory. TWiki will pick them up properly, even if the meta data is missing. I did this for example to web-enable bug tracking data of a proprietary bug tracker. Each bug was dumped by a plugin into a text file in a TWiki web and as referenceable and searcheable within TWiki.

You can even generate .txt files with proper meta data for TWikiForms, that way you can create reports easily with a formatted VarSEARCH. As an example, look at the raw text of this topic to see the format of the TWiki Form meta data.

If you want to read external data within a plugin and create topics you can use the TWiki::Func::readFile() function.

One other option is to dump your log files to any web enabled directory, could be on a server different from TWiki. From any TWiki page you can INCLUDE that log data. If you format the data to TML you will get nice formatting, such as TWiki tables.

-- PeterThoeny - 03 Mar 2008

Change status to:
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2008-04-05 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.