aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Durango/ServiceConfig/MakeZips.py
blob: 9b911002b481e81f81f531b4aa648b7f90481eb6 (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
54
55
56
57
58
59
60
61
62
import os
import shutil
import zipfile

# 4J-JEV: Takes:
#	- Localisation from 'ServiceConfig\loc\ex-EX\index.html'
#	- Template help from 'ServiceConfig\HelpDocument\*'
#
# Then:
#	- Constructs all zipped files to 'ServiceConfig\HelpDocument_ex-EX.zip'.
#
# NOTE: Make sure to check out 'ServiceConfig\HelpDocument\*' first.

def formatLoc(str):
	[lang,local] = str.split('-')
	return ( lang.lower() + "-" + local.upper() )

def copyTemplate(dst):
	for root, dirs, files in os.walk(".\\HelpDocument\\"):
		if not os.path.exists(dst+"\\"+root):
			os.makedirs(dst+"\\"+root)
	
		for f in filter(lambda x: x!="index.html", files):
			if not os.path.isdir(root+"\\"+f):
				print "Copying to '%s\\%s\\%s'" % (dst,root,f)
				shutil.copyfile(root+"\\"+f, dst+"\\"+root+"\\"+f)

def createZip(name):
	os.chdir(".\\"+name)

	zipname = name+".zip"
	print "Created "+zipname
	
	z = zipfile.ZipFile(zipname, 'w')
	for root, dirs, files in os.walk(".\\HelpDocument\\"):
		for file in files:
			print "Adding '%s\\%s'." % (root,file)
			z.write(os.path.join(root,file))
			
	z.close()
	
	shutil.move(".\\"+zipname, "..\\"+zipname)
	os.chdir("..")

	
	
						#== MAIN ==#	
						
if __name__=="__main__":
	for loc in map(formatLoc,os.listdir(".\\loc\\")):
		tardir = ".\\HelpDocument_"+loc
		
		if os.path.isdir(tardir):
			shutil.rmtree(tardir)
		copyTemplate(tardir+"\\")
		
		print ( "Making '%s'" % tardir )
		shutil.copy(".\\loc\\"+loc+"\\index.html",tardir+"\\HelpDocument\\index.html")
		
		createZip(tardir)
		shutil.rmtree(tardir)