~vono22/narau/trunk

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python

#    Copyright (C) 2012 Yvon TANGUY
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import hashlib
import gzip
import re
import sqlite3

GZIP_EXT=".gz"
DB_DICT_PATTERN='^dict_[a-z]{3}-[0-9]+\.db$'
DB_KANJI_PATTERN='^kanjis_[a-z]{3}-[0-9]+\.db$'
VERSION_CODE_PATTERN='( *android:versionCode=\")([0-9]+)(\")'

def printFileInfo(db_filename):
	# stat the db file
	os.stat_float_times(False)
	fStat = os.stat(db_filename)
	db_size = str(fStat.st_size)

	gz_filename = db_filename + GZIP_EXT
	db_creation_time = None
	# db_version = "<insert db version>"

	connect = sqlite3.connect(db_filename)
	with connect:
		cursor = connect.cursor()
		cursor.execute("select value_int from db_info where key='creation_time'")
		data = cursor.fetchone()
		if data:
			db_creation_time = str(data[0])
		# cursor.execute("select value_int from db_info where key='version'")
		# data = cursor.fetchone()
		# if data:
		#	db_version = str(data[0])


	# compress the file in GZip:
	f_in = open(db_filename, 'rb')
	f_out = gzip.open(gz_filename, 'wb', 9)
	f_out.writelines(f_in)
	f_out.close()
	f_in.close()

	# stat the gz file
	fStat = os.stat(gz_filename)
	gz_size = str(fStat.st_size)
	if not db_creation_time:
		db_creation_time = str(fStat.st_mtime)

	# calc md5 sum:
	md5 = hashlib.md5()
	try:
		file = open(gz_filename, "rb")
		buff = file.read(4096)
		while buff:
			md5.update(buff)
			buff = file.read(4096)	
	except e:
		print(str(e))
	finally:
		file.close()
	gz_md5 = md5.hexdigest()
	
	# print the result:
	print(db_filename + " " + db_creation_time + " " + db_size + " " + gz_size + " " + gz_md5 + " <insert urls>")

	# remove the original db file
	os.remove(db_filename)

version_code="0"
with open('../Narau/AndroidManifest.xml') as manifest:
	lines = manifest.readlines()
	regex = re.compile(VERSION_CODE_PATTERN)
	for line in lines:
		match = regex.match(line)
		if match:
			version_code = match.group(2)
			break

print("# db_filename db_creation_time db_size gz_size gz_md5 gz_download_url_1 gz_download_url_2...")
print("NarauVersionCode:" + version_code)

# Dictionary databases:
regex = re.compile(DB_DICT_PATTERN)
files = os.listdir('.')
files.sort()
for file in files:
	if regex.match(file):
		printFileInfo(file)
		pass
	pass

# Kanji databases:
regex = re.compile(DB_KANJI_PATTERN)
files = os.listdir('.')
files.sort()
for file in files:
	if regex.match(file):
		printFileInfo(file)
		pass
	pass

# print a new line:
print