~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to install/install.py

  • Committer: V. Keith Hughitt
  • Date: 2008-07-09 18:59:47 UTC
  • Revision ID: hughitt1@kore-20080709185947-lsdp2jwnuc1bs5nd
nightly build 07-09-2008: re-writing db population script to fix errors during tile processing

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
import os, glob, math
 
5
 
 
6
def main():
 
7
    printGreeting()
 
8
    path, dbname = getInput()
 
9
    #traverseDirectory(path)
 
10
    traverseTiles(path)
 
11
 
 
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)
 
18
        else:
 
19
            processTile(os.path.split(node)[1]);
 
20
 
 
21
def traverseTiles (path):
 
22
    ''' Travels to the each of the lowest-level child directories and
 
23
        processes tiles found there.'''
 
24
 
 
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, '*/*/*/*/*/*/*'))
 
28
 
 
29
    for dir in leafDirs:
 
30
        processImages(dir)
 
31
        #processTiles(dir)
 
32
 
 
33
def processImages (dir):
 
34
    ''' populate images table with images from a single directory '''
 
35
    times = []
 
36
 
 
37
    #get times of observations in current directory
 
38
    for file in os.listdir(dir):
 
39
        times.append(file[13:17])
 
40
 
 
41
    #get rid of redudant entries
 
42
    times = compact(times)
 
43
 
 
44
    print "times"
 
45
    for i in times:
 
46
        print i
 
47
 
 
48
#old
 
49
def processTile (tile):
 
50
    time =      tile[11:17]
 
51
    zoomLevel = tile[35:37]
 
52
    #print zoomLevel + ', ' + time
 
53
 
 
54
def printGreeting():
 
55
    ''' Prints a greeting to the user'''
 
56
    os.system("clear")
 
57
 
 
58
    print "====================================================================="
 
59
    print "= HelioViewer Database Population Script 0.1                        ="
 
60
    print "= By: Keith Hughitt, July 08, 2008                                  ="
 
61
    print "=                                                                   ="
 
62
    print "= This script processes raw tile images, and inserts them into a    ="
 
63
    print "= database, along with their relevent information.                  ="
 
64
    print "=                                                                   ="
 
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 "====================================================================="
 
73
 
 
74
def getInput():
 
75
    ''' Prompts the user for required information '''
 
76
 
 
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: ")
 
81
 
 
82
    dbname = raw_input("Database name: ")
 
83
    return path, dbname
 
84
    #dbuser = raw_input("Database user: ")
 
85
    #dbpass = raw_input("Database password: ")
 
86
 
 
87
def getNumTiles (zoomLevel):
 
88
    ''' Returns the number of tiles expected for a given zoom-level '''
 
89
 
 
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))
 
93
 
 
94
 
 
95
def compact(seq):
 
96
    '''Removes duplicate entries from a list.
 
97
       From http://www.peterbe.com/plog/uniqifiers-benchmark'''
 
98
    seen = set()
 
99
    return [ x for x in seq if x not in seen and not seen.add(x)]
 
100
 
 
101
 
 
102
if __name__ == '__main__':
 
103
    main()