1
1
# -*- coding: utf-8 -*-
2
"""A text-based installer for Helioviewer.org"""
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 *
7
11
class HelioviewerConsoleInstaller:
12
"""Text-based installer class"""
9
13
def __init__(self, options):
10
14
self.options = options
12
16
def getFilePath(self):
13
''' Prompts the user for the directory information '''
17
'''Prompts the user for the directory information'''
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: ")
24
28
dbtypes = {1: "mysql", 2: "postgres"}
27
print "Please select the desired database to use for installation:"
29
print " [2] PostgreSQL"
30
choice = int(raw_input("Choice: "))
31
print("Please select the desired database to use for installation:")
33
print(" [2] PostgreSQL")
34
choice = get_input("Choice: ")
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.")
35
return dbtypes[choice]
39
return dbtypes[int(choice)]
37
41
def getDatabasename(self):
38
42
''' Prompts the user for the database name '''
40
dbname = raw_input(" Database name [helioviewer]: ")
44
dbname = get_input(" Database name [helioviewer]: ")
43
47
if not dbname: dbname = "helioviewer"
49
53
options = {1: True, 2: False}
52
print "Would you like to create the database schema used by Helioviewer.org?:"
55
choice = int(raw_input("Choice: "))
56
print("Would you like to create the database schema used by "
60
choice = get_input("Choice: ")
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.")
60
return options[choice]
65
return options[int(choice)]
62
67
def getDatabaseInfo(self):
63
68
''' Gets database type and administrator login information '''
67
dbtype = self.getDatabaseType()
68
dbuser = raw_input(" Username: ")
72
dbtype = self.getDatabaseType()
73
dbuser = get_input(" Username: ")
69
74
dbpass = getpass.getpass(" Password: ")
72
if not dbuser: dbuser = "root"
75
# mysql = True if dbtype is "mysql" else False
81
mysql = dbtype is "mysql"
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.")
84
87
return dbuser,dbpass,mysql
119
124
path = app.getFilePath()
121
126
# Locate jp2 images in specified filepath
122
images = traverseDirectory(path)
127
images = traverse_directory(path)
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.")
129
print "Found %d JPEG2000 images." % len(images)
134
print("Found %d JPEG2000 images." % len(images))
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()
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()
143
148
# Setup database schema
144
cursor = setupDatabaseSchema(dbuser, dbpass, dbname, hvuser, hvpass, mysql)
149
cursor = setup_database_schema(dbuser, dbpass, dbname, hvuser, hvpass,
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()
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()
154
cursor = getDatabaseCursor(dbname, dbuser, dbpass, mysql)
159
cursor = get_db_cursor(dbname, dbuser, dbpass, mysql)
156
print "Processing Images..."
161
print("Processing Images...")
158
163
# Insert image information into database
159
processJPEG2000Images(images, path, cursor, mysql)
161
#print("Creating database index")
162
#createDateIndex(cursor)
164
process_jp2_images(images, path, cursor, mysql)
168
169
def loadUpdater(options):
169
170
''' Loads the text-based installation tool and runs it in update-mode '''
170
171
app = HelioviewerConsoleInstaller(options)
173
if options.dbtype == "mysql":
174
mysql = options.dbtype == "mysql"
178
cursor = getDatabaseCursor(options.dbname, options.dbuser, options.dbpass, mysql)
176
cursor = get_db_cursor(options.dbname, options.dbuser, options.dbpass, mysql)
180
print "Processing Images..."
178
print("Processing Images...")
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)
190
# CREATE INDEX date_index USING BTREE ON image (date);
188
if sys.version_info[0] >= 3:
191
get_input = raw_input
b'\\ No newline at end of file'