Mailing List Archive

Upload macro
Ok this is my first trac macro AND my first python script, and while it
works I need some help improving it.

The script creates a download link and how many times the file was
downloaded.

Right now it accesses the counter file directly and the download path is
built in.. I would like to be able to put these in a projects config
file but I don't know how to add/access the variables.


def execute(hdf, txt, env):
import string
# Currently hdf is set only when the macro is called
# From a wiki page
if hdf:
hdf.setValue('wiki.macro.greeting', 'Upload Count')



# args will be null if the macro is called without parentesis.
args = txt or 'No File'
fileobject =
open("/home/projects.cyberlot.net/www/downloads/counter.txt", "r")
downloads = 0
while 1:
line = fileobject.readline()
if not line:
break
pos = string.find(line, args)
if pos == 0:
downloads = downloads + 1
fileobject.close()
return '<a href="http://projects.cyberlot.net/downloads/?file=' +
args + '">' + args + '</a> Downloaded ' + str(downloads) + ' Times '


--
Richard Thomas
Cyberlot Technologies Group Inc.
507.398.4124 - Voice