2
# -*- coding: utf-8 -*-
8
path, dbname = getInput()
9
#traverseDirectory(path)
12
def traverseDirectory (path):
13
''' Traverses file-tree starting with the specified path'''
14
for child in os.listdir(path):
15
node = os.path.join(path, child)
16
if os.path.isdir(node):
17
traverseDirectory(node)
19
processTile(os.path.split(node)[1]);
21
def traverseTiles (path):
22
''' Travels to the each of the lowest-level child directories and
23
processes tiles found there.'''
25
#Find lowest-level directories. Assumes that search is starting at the
26
#root directory (one containing year directories).
27
leafDirs = glob.glob (os.path.join(path, '*/*/*/*/*/*/*'))
33
def processImages (dir):
34
''' populate images table with images from a single directory '''
37
#get times of observations in current directory
38
for file in os.listdir(dir):
39
times.append(file[13:17])
41
#get rid of redudant entries
42
times = compact(times)
49
def processTile (tile):
51
zoomLevel = tile[35:37]
52
#print zoomLevel + ', ' + time
55
''' Prints a greeting to the user'''
58
print "====================================================================="
59
print "= HelioViewer Database Population Script 0.1 ="
60
print "= By: Keith Hughitt, July 08, 2008 ="
62
print "= This script processes raw tile images, and inserts them into a ="
63
print "= database, along with their relevent information. ="
65
print "= The script requires several pieces of information to function: ="
66
print "= (1) The location of the root directory where tiles are stored. ="
67
print "= This is the directory whose sub-directories are years: ="
68
print "= 2003, 2004, etc. ="
69
print "= (2) The name of the database schema to populate. ="
70
print "= (3) The name of the database user with appropriate access. ="
71
print "= (4) The password for the specified database user. ="
72
print "====================================================================="
75
''' Prompts the user for required information '''
77
path = raw_input("Root directory: ")
78
while not os.path.isdir(path):
79
print "That is not a valid directory! Please try again."
80
path = raw_input("Root directory: ")
82
dbname = raw_input("Database name: ")
84
#dbuser = raw_input("Database user: ")
85
#dbpass = raw_input("Database password: ")
87
def getNumTiles (zoomLevel):
88
''' Returns the number of tiles expected for a given zoom-level '''
90
#Each image above zoom-level 11 consists of 4 tiles, for zoom Levels
91
#below that, the number of tiles is 3^2, 4^2, etc.
92
return int(4 if zoomLevel >= 12 else math.pow((14 - zoomLevel), 2))
96
'''Removes duplicate entries from a list.
97
From http://www.peterbe.com/plog/uniqifiers-benchmark'''
99
return [ x for x in seq if x not in seen and not seen.add(x)]
102
if __name__ == '__main__':