aboutsummaryrefslogtreecommitdiffstats
path: root/util/updatetpl.py
blob: 1319387c6a4729a000539084fb2f98cf6056e8ee (plain) (blame)
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
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
#
# Script to update Smarty template files from all internal templates
# Copyright 2013 Zach Prezkuta
# Licensed under GPL v3


import os
import sys, getopt
import subprocess


def help(pname):
	print "\nUsage:"
	print "\t" + pname + " -h\n\n\t\t\tShow this help screen\n"
	print "\t" + pname + " -p directory\n\n\t\t\tConvert all .tpl files in top-level\n\t\t\tFriendica directory to Smarty templates\n"
	print "\t" + pname + "\n\n\t\t\tInteractive mode\n"



#
# Main script
#

path = ''

try:
	opts, args = getopt.getopt(sys.argv[1:], "hp:")
	for opt, arg in opts:
		if opt == '-h':
			help(sys.argv[0])
			sys.exit()
		elif opt == '-p':
			path = arg
except getopt.GetoptError:
	help(sys.argv[0])
	sys.exit(2)

if path == '':
	path = raw_input('Path to top-level Friendica directory: ')

if path[-1:] != '/':
	path = path + '/'

excludepaths = ['css', 'img', 'js', 'php', 'theme']
tplpaths = []
names = os.listdir(path + 'view/')
for name in names:
	if os.path.isdir(path + 'view/' + name):
		if name not in excludepaths:
			tplpaths.append('view/' + name + '/')

names = os.listdir(path + 'view/theme/')
for name in names:
	if os.path.isdir(path + 'view/theme/' + name):
		tplpaths.append('view/theme/' + name + '/tpl/')

fnull = open(os.devnull, "w")

for tplpath in tplpaths:
	print "Converting " + path + tplpath
	subprocess.call(['python', path + 'mods/friendica-to-smarty-tpl.py', '-p', path + tplpath], stdout = fnull)

fnull.close()