~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to install/org/helioviewer/HelioviewerConsoleInstaller.py

  • Committer: Keith Hughitt
  • Date: 2011-05-26 19:28:41 UTC
  • mfrom: (402.1.667 hv)
  • Revision ID: keith.hughitt@nasa.gov-20110526192841-5xmuft9jsm52pzih
Helioviewer.org 2.2.0 Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
import sys, os
 
2
"""A text-based installer for Helioviewer.org"""
 
3
import sys
 
4
import os
 
5
import math
 
6
import getpass
 
7
from datetime import datetime
3
8
from org.helioviewer.jp2 import *
4
9
from org.helioviewer.db  import *
5
 
from org.helioviewer.utils import *
6
10
 
7
11
class HelioviewerConsoleInstaller:
8
 
 
 
12
    """Text-based installer class"""
9
13
    def __init__(self, options):
10
14
        self.options = options
11
15
        
12
16
    def getFilePath(self):
13
 
        ''' Prompts the user for the directory information '''
 
17
        '''Prompts the user for the directory information'''
14
18
    
15
 
        path = raw_input("Location of JP2 Images: ")
 
19
        path = get_input("Location of JP2 Images: ")
16
20
        while not os.path.isdir(path):
17
 
            print "That is not a valid directory! Please try again."
18
 
            path = raw_input("Location of JP2 Images: ")
 
21
            print("That is not a valid directory! Please try again.")
 
22
            path = get_input("Location of JP2 Images: ")
19
23
    
20
24
        return path
21
25
    
24
28
        dbtypes = {1: "mysql", 2: "postgres"}
25
29
        
26
30
        while True:
27
 
            print "Please select the desired database to use for installation:"
28
 
            print "   [1] MySQL"
29
 
            print "   [2] PostgreSQL"
30
 
            choice = int(raw_input("Choice: "))
 
31
            print("Please select the desired database to use for installation:")
 
32
            print("   [1] MySQL")
 
33
            print("   [2] PostgreSQL")
 
34
            choice = get_input("Choice: ")
31
35
            
32
 
            if choice not in [1,2]:
33
 
                print "Sorry, that is not a valid choice."
 
36
            if choice not in ['1', '2']:
 
37
                print("Sorry, that is not a valid choice.")
34
38
            else:
35
 
                return dbtypes[choice]
 
39
                return dbtypes[int(choice)]
36
40
            
37
41
    def getDatabasename(self):
38
42
        ''' Prompts the user for the database name '''
39
43
 
40
 
        dbname = raw_input("    Database name [helioviewer]: ")
 
44
        dbname = get_input("    Database name [helioviewer]: ")
41
45
   
42
46
        # Default values
43
47
        if not dbname: dbname = "helioviewer"
49
53
        options = {1: True, 2: False}
50
54
        
51
55
        while True:
52
 
            print "Would you like to create the database schema used by Helioviewer.org?:"
53
 
            print "   [1] Yes"
54
 
            print "   [2] No"
55
 
            choice = int(raw_input("Choice: "))
 
56
            print("Would you like to create the database schema used by "
 
57
                  "Helioviewer.org?:")
 
58
            print("   [1] Yes")
 
59
            print("   [2] No")
 
60
            choice = get_input("Choice: ")
56
61
            
57
 
            if choice not in [1,2]:
58
 
                print "Sorry, that is not a valid choice."
 
62
            if choice not in ['1', '2']:
 
63
                print("Sorry, that is not a valid choice.")
59
64
            else:
60
 
                return options[choice]
 
65
                return options[int(choice)]
61
66
    
62
67
    def getDatabaseInfo(self):
63
68
        ''' Gets database type and administrator login information '''
64
69
        import getpass
65
70
        
66
71
        while True:  
67
 
            dbtype    = self.getDatabaseType()
68
 
            dbuser     = raw_input("    Username: ")        
 
72
            dbtype = self.getDatabaseType()
 
73
            dbuser = get_input("    Username: ")        
69
74
            dbpass = getpass.getpass("    Password: ")
70
75
        
71
76
            # Default values
72
 
            if not dbuser: dbuser = "root"
 
77
            if not dbuser:
 
78
                dbuser = "root"
73
79
 
74
80
            # MySQL?
75
 
            # mysql = True if dbtype is "mysql" else False
76
 
            if dbtype is "mysql":
77
 
                mysql = True
78
 
            else:
79
 
                mysql = False
 
81
            mysql = dbtype is "mysql"
80
82
            
81
 
            if not checkDBInfo(dbuser, dbpass, mysql):
82
 
                print "Unable to connect to the database. Please check your login information and try again."
 
83
            if not check_db_info(dbuser, dbpass, mysql):
 
84
                print("Unable to connect to the database. Please check your "
 
85
                      "login information and try again.")
83
86
            else:
84
87
                return dbuser,dbpass,mysql        
85
88
 
87
90
        ''' Prompts the user for the required database information '''
88
91
 
89
92
        # Get new user information (Todo 2009/08/24: validate input form)
90
 
        dbuser = raw_input("    Username [helioviewer]: ")
91
 
        dbpass = raw_input("    Password [helioviewer]: ")
 
93
        dbuser = get_input("    Username [helioviewer]: ")
 
94
        dbpass = get_input("    Password [helioviewer]: ")
92
95
    
93
96
        # Default values
94
 
        if not dbuser: dbuser = "helioviewer"
95
 
        if not dbpass: dbpass = "helioviewer"
 
97
        if not dbuser:
 
98
            dbuser = "helioviewer"
 
99
        if not dbpass:
 
100
            dbpass = "helioviewer"
96
101
    
97
102
        return dbuser, dbpass
98
103
 
100
105
        ''' Prints a greeting to the user'''
101
106
        os.system("clear")
102
107
        
103
 
        print """\
 
108
        print("""\
104
109
====================================================================
105
110
= Helioviewer Database Population Script                           =
106
111
= Last updated: 2010/10/07                                         =
108
113
= This script processes JP2 images, extracts their associated      =
109
114
= meta-information and stores it away in a database.               =
110
115
=                                                                  =
111
 
===================================================================="""
 
116
====================================================================""")
112
117
 
113
118
def loadTextInstaller(options):
114
119
    ''' Loads the text-based installation tool '''
119
124
    path = app.getFilePath()
120
125
    
121
126
    # Locate jp2 images in specified filepath
122
 
    images = traverseDirectory(path)
 
127
    images = traverse_directory(path)
123
128
    
124
129
    # Check to make sure the filepath contains jp2 images
125
130
    if len(images) is 0:
126
 
        print "No JPEG 2000 images found. Exiting installation."
 
131
        print("No JPEG 2000 images found. Exiting installation.")
127
132
        sys.exit(2)
128
133
    else:
129
 
        print "Found %d JPEG2000 images." % len(images)
 
134
        print("Found %d JPEG2000 images." % len(images))
130
135
 
131
136
    # Setup database schema if needed
132
137
    if (app.shouldSetupSchema()):
133
 
        print "Please enter new database information:"
 
138
        print("Please enter new database information:")
134
139
        dbname = app.getDatabasename()
135
140
        hvuser, hvpass = app.getNewUserInfo()
136
141
        
137
 
        print ""
 
142
        print("")
138
143
        
139
144
        # Get database information
140
 
        print "Please enter existing database admin information:"
 
145
        print("Please enter existing database admin information:")
141
146
        dbuser, dbpass, mysql = app.getDatabaseInfo()
142
147
 
143
148
        # Setup database schema
144
 
        cursor = setupDatabaseSchema(dbuser, dbpass, dbname, hvuser, hvpass, mysql)
 
149
        cursor = setup_database_schema(dbuser, dbpass, dbname, hvuser, hvpass, 
 
150
                                       mysql)
145
151
    
146
152
    else:
147
153
        # Get database information
148
 
        print "Please enter Helioviewer.org database name"
 
154
        print("Please enter Helioviewer.org database name")
149
155
        dbname = app.getDatabasename()
150
156
        
151
 
        print "Please enter Helioviewer.org database user information"
 
157
        print("Please enter Helioviewer.org database user information")
152
158
        dbuser, dbpass, mysql = app.getDatabaseInfo()
153
 
        
154
 
        cursor = getDatabaseCursor(dbname, dbuser, dbpass, mysql)
 
159
        cursor = get_db_cursor(dbname, dbuser, dbpass, mysql)
155
160
 
156
 
    print "Processing Images..."
 
161
    print("Processing Images...")
157
162
 
158
163
    # Insert image information into database
159
 
    processJPEG2000Images(images, path, cursor, mysql)
160
 
    
161
 
    #print("Creating database index")        
162
 
    #createDateIndex(cursor)
163
 
    
 
164
    process_jp2_images(images, path, cursor, mysql)
164
165
    cursor.close()
165
166
 
166
 
    print "Finished!"
 
167
    print("Finished!")
167
168
    
168
169
def loadUpdater(options):
169
170
    ''' Loads the text-based installation tool and runs it in update-mode '''
170
171
    app = HelioviewerConsoleInstaller(options)
171
172
    
172
173
    # MySQL?
173
 
    if options.dbtype == "mysql":
174
 
        mysql = True
175
 
    else:
176
 
        mysql = False
 
174
    mysql = options.dbtype == "mysql"
177
175
        
178
 
    cursor = getDatabaseCursor(options.dbname, options.dbuser, options.dbpass, mysql)
 
176
    cursor = get_db_cursor(options.dbname, options.dbuser, options.dbpass, mysql)
179
177
 
180
 
    print "Processing Images..."
 
178
    print("Processing Images...")
181
179
 
182
180
    # Insert image information into database
183
 
    processJPEG2000Images(options.files, options.basedir, cursor, mysql)
 
181
    process_jp2_images(options.files, options.basedir, cursor, mysql)
184
182
    
185
183
    cursor.close()
186
184
 
187
 
    print "Finished!"
 
185
    print("Finished!")
188
186
    
189
 
# Add Index
190
 
# CREATE INDEX date_index USING BTREE ON image (date);
 
187
# raw_input
 
188
if sys.version_info[0] >= 3:
 
189
    get_input = input
 
190
else:
 
191
    get_input = raw_input
191
192
 
192
 
#print "Finished!"
 
 
b'\\ No newline at end of file'