File: make-www-archive.py

package info (click to toggle)
scummvm 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 138,796 kB
  • sloc: cpp: 1,855,329; ansic: 59,124; asm: 28,745; sh: 8,110; python: 4,556; perl: 2,903; xml: 2,507; makefile: 1,155; java: 944; yacc: 502; lex: 322; objc: 81; sed: 22; php: 1
file content (48 lines) | stat: -rwxr-xr-x 1,223 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python
# encoding: utf-8
import sys
import re
import os
import zipfile
import argparse

ARCHIVE_FILE_EXTENSIONS = ('.html', '.css', '.js', '.ico', '.png')

def buildArchive(archiveName):
	if not os.path.isdir(archiveName):
		print ("Invalid archive name: " + archiveName)
		return

	zf = zipfile.ZipFile(archiveName + ".zip", 'w')

	print ("Building '" + archiveName + "' archive:")
	os.chdir(archiveName)

	directories = ['.', './icons']
	for d in directories:
		filenames = os.listdir(d)
		filenames.sort()
		for filename in filenames:
			if os.path.isfile(d + '/' + filename) and filename.endswith(ARCHIVE_FILE_EXTENSIONS):
				zf.write(d + '/' + filename, d + '/' + filename)
				print ("    Adding file: " + d + '/' + filename)

	os.chdir('../')

	zf.close()

def main():
	parser = argparse.ArgumentParser(description='Generates wwwroot archive')
	parser.add_argument('path', nargs='?', help='path where the wwwroot source data can be found')
	args = parser.parse_args()
	if args.path != None:
		if not os.path.isdir(args.path):
			print ("Directory '" + args.path + "' does not exist!")
			return
		else:	
			os.chdir(args.path)
	
	buildArchive("wwwroot")

if __name__ == "__main__":
	sys.exit(main())