summaryrefslogtreecommitdiffstats
path: root/silpa/utils/silpautils.py
blob: 25a3df868c8d18b336831fad10e5c0ec71c2568c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import codecs
def getTemplate():
	return open(getTemplateName()).read()
def getTemplateName():
	return loadConfiguration()["SILPA_TEMPLATE"]	
def getCopyrightInfo():
	return loadConfiguration()["SILPA_SITE_COPYRIGHT"]		
def getModulesList():
	conf_dict=loadConfiguration()
	action_dict={}
	for item in conf_dict	:
		if(item.startswith("SILPA_ACTION.")):
			action_dict[item.replace("SILPA_ACTION.","")]=conf_dict[item]
	return 	action_dict	
def getStaticContent(page):
	try:
		return open("doc/"+page).read()
	except:
		return "Could not find the requested page "+	page
def handleStats():
	Hits="0"	
	try:
		InFile = open("count.dat", "r")	# Text file with total hits
		Hits = InFile.readline()
	except:
		pass	
	x = int(Hits) + 1
	h = str(x)
	OutFile = open("count.dat", "w")
	OutFile.write(str(x))
	OutFile.close()

def loadConfiguration():
	conf_dict={}
	conffile = codecs. open("silpa.conf",encoding='utf-8', errors='ignore')
	while 1:
		text = unicode( conffile.readline())
		if text == "":
			  break
		line = text.split("#")[0].strip()
		if(line == ""):
			  continue 
		try:	  
			lhs = line.split("=") [ 0 ]  
			rhs = line.split("=") [ 1 ]  
			conf_dict[lhs]=rhs
		except:
			pass	
	return conf_dict
if __name__ == '__main__':
	print getModulesList()