-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix makemysql so that easywp might work #154
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3190152
rewrote so that it might work
axmmisaka 6596e3a
idk wat autopep8 changed/suggested i followed its advice
axmmisaka f2b495c
forgot to add the messages
axmmisaka 06d1355
Added argument parsing and non-human-friendly output
axmmisaka 7cdbb58
Squashed two commits
axmmisaka e43bdb5
updated all three scripts so that they support some silent arguments …
axmmisaka ea004ec
fix stupid bugs made in 3cac9d4d
axmmisaka 9cf60d7
fix pre-commit problem made in 3cac9d4d
axmmisaka ef8816f
Wrapper for if silent
axmmisaka 5e9b52d
Fixed a stupid logical mistake and added some stuff in bash scripts; …
axmmisaka 2798e6b
Applied @kpengboy's suggestions
axmmisaka 6aa0b56
Bug: if quite is specified, do not ask if user wants to proceed.
axmmisaka 7431eef
Indentation Errors
axmmisaka 0c19f5a
Fix, silent should be global variable
axmmisaka 6b7b2c3
Fixed some bugs in easywp
axmmisaka 7fe6f5c
fix comment
axmmisaka 051e038
fix so precommit pass
axmmisaka bb20eb4
more to squash
axmmisaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ MYSQL_HOST = 'mysql.ocf.berkeley.edu' | |
|
||
PW_LENGTH = 24 | ||
|
||
quiet = False | ||
|
||
|
||
def read_config(): | ||
"""Fetches the MySQL hostname and root password from the config in | ||
|
@@ -47,6 +49,11 @@ def read_config(): | |
return mysql_host, mysql_root_pw | ||
|
||
|
||
def print_if_not_quiet(*args, **kwargs): | ||
if not quiet: | ||
print(*args, **kwargs) | ||
|
||
|
||
def intro_prompt(): | ||
print(dedent( | ||
""" | ||
|
@@ -69,6 +76,8 @@ def intro_prompt(): | |
|
||
|
||
def main(): | ||
# Without this quiet below will be local variable | ||
global quiet | ||
try: | ||
username = os.environ.get('SUDO_USER') | ||
|
||
|
@@ -78,43 +87,45 @@ def main(): | |
# Read config file. | ||
mysql_host, mysql_root_pw = read_config() | ||
|
||
# Added a simple and stupid argument parsing so that other scripts can use it without tunneling in yes. | ||
if len(sys.argv) > 1 and sys.argv[1] in ['-q', '--quiet']: | ||
quiet = True | ||
# Check whether the script should proceed. | ||
if not intro_prompt(): | ||
print('>>> Aborted by user request.') | ||
return | ||
|
||
if not quiet: | ||
if not intro_prompt(): | ||
print_if_not_quiet('>>> Aborted by user request.', file=sys.stderr) | ||
return | ||
# Connect to the MySQL server. | ||
try: | ||
print('>>> Connecting to MySQL database server...') | ||
print_if_not_quiet('>>> Connecting to MySQL database server...') | ||
connection = MySQLdb.connect(host=mysql_host, | ||
user='root', | ||
passwd=mysql_root_pw) | ||
except MySQLdb.MySQLError: | ||
print('>>> Error: Failed to connect to MySQL server.') | ||
raise | ||
raise ConnectionError('>>> Error: Failed to connect to MySQL server.') | ||
|
||
# Check if the database already exists. | ||
try: | ||
print(">>> Checking if database '{}' already exists...".format(username)) | ||
print_if_not_quiet(">>> Checking if database '{}' already exists...".format(username)) | ||
connection.select_db(username) | ||
|
||
# The database already exists, so skip the creation step. | ||
print('yes.') | ||
print_if_not_quiet('yes.') | ||
db_create = False | ||
print(dedent(""" | ||
The MySQL database '{}' already exists. | ||
The database password will be reset. | ||
print_if_not_quiet(dedent(""" | ||
The MySQL database '{}' already exists. | ||
The database password will be reset. | ||
|
||
If you are unsure how to access or use your database, please visit | ||
If you are unsure how to access or use your database, please visit | ||
|
||
https://www.ocf.berkeley.edu/docs/services/mysql/ | ||
https://www.ocf.berkeley.edu/docs/services/mysql/ | ||
|
||
If you run into trouble trying to use your database, contact us at | ||
If you run into trouble trying to use your database, contact us at | ||
|
||
[email protected] | ||
""").format(username)) | ||
[email protected] | ||
""").format(username)) | ||
except MySQLdb.OperationalError: | ||
print('no.') | ||
print_if_not_quiet('no.') | ||
db_create = True | ||
|
||
# Add or update user database privileges. | ||
|
@@ -128,37 +139,39 @@ def main(): | |
# Result should be "Query OK, 0 rows affected", | ||
# but we'll assume no exception means success. | ||
except MySQLdb.MySQLError: | ||
print('>>> Error: Failed to grant database privileges.') | ||
raise | ||
raise ConnectionError('>>> Error: Failed to grant database privileges.') | ||
|
||
# Create new database, if necessary. | ||
if db_create: | ||
try: | ||
print(">>> Creating new database '{}'...".format(username)) | ||
print_if_not_quiet(">>> Creating new database '{}'...".format(username)) | ||
query = CREATE_QUERY.format(username) | ||
connection.query(query) | ||
connection.store_result() | ||
# Result should be "Query OK, 1 row affected", | ||
# but we'll assume no exception means success. | ||
except MySQLdb.MySQLError: | ||
print('>>> Error: Failed to create database.') | ||
raise | ||
raise IOError('>>> Error: Failed to create database.') | ||
|
||
# Database is ready for use. | ||
if db_create: | ||
print(dedent(""" | ||
Your MySQL database has been created. | ||
print_if_not_quiet(dedent(""" | ||
Your MySQL database has been created. | ||
|
||
For instructions on accessing and using your database, please visit | ||
|
||
For instructions on accessing and using your database, please visit | ||
https://www.ocf.berkeley.edu/docs/services/mysql/ | ||
|
||
https://www.ocf.berkeley.edu/docs/services/mysql/ | ||
If you run into trouble trying to use your database, contact us at | ||
|
||
If you run into trouble trying to use your database, contact us at | ||
[email protected] | ||
""")) | ||
|
||
[email protected] | ||
""")) | ||
print_if_not_quiet('>>> Your MySQL database password is: ') | ||
|
||
print('>>> Your MySQL database password is: {}'.format(userpass)) | ||
# This line to be printed, no matter quiet or not. | ||
# The userpass will always be on the last line. | ||
print(userpass) | ||
except Exception as ex: | ||
send_problem_report(dedent( | ||
"""\ | ||
|
@@ -171,8 +184,9 @@ def main(): | |
""" | ||
A fatal error was encountered during program execution. | ||
OCF staff have been notified of the problem. | ||
""" | ||
)) | ||
Error for staff: {}: {}. | ||
""".format(ex.__class__.__name__, ex) | ||
), file=sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these be
if [[ $? -ne 0 ]]
? Since we are checking if the return code was abnormal (0 is success)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you inverted this in
051e0387350c67f0fd6cf976da25ad8511ad46bb
to make precommit pass. What was the issue?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why but pre-commit say I should use
if [ $? ]
instead ofif [[ $? -ne 0 ]]
so I accepted this recommendation