Added Python3 compatibility to print statements (#220)

This commit is contained in:
Thomas Gerot
2017-03-07 23:43:52 -06:00
committed by Kevin Chung
parent 41eaa56232
commit a390a06861

View File

@@ -30,16 +30,16 @@ def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
## Copy over flags data to Keys table ## Copy over flags data to Keys table
print "Getting bind..." print("Getting bind...")
conn = op.get_bind() conn = op.get_bind()
print "Executing: SELECT id, flags from challenges" print("Executing: SELECT id, flags from challenges")
res = conn.execute(text("SELECT id, flags from challenges")) res = conn.execute(text("SELECT id, flags from challenges"))
results = res.fetchall() results = res.fetchall()
print "There are {} results".format(len(results)) print("There are {} results".format(len(results)))
new_keys = [] new_keys = []
print "Processing existing flags" print("Processing existing flags")
for r in results: for r in results:
if r[1]: ## Check if flags are NULL if r[1]: ## Check if flags are NULL
data = json.loads(r[1]) data = json.loads(r[1])
@@ -48,44 +48,44 @@ def upgrade():
if new_keys: if new_keys:
## Base CTFd databases actually already insert into Keys but the database does not make use of them ## Base CTFd databases actually already insert into Keys but the database does not make use of them
## This prevents duplicate entries of keys ## This prevents duplicate entries of keys
print "Executing: TRUNCATE keys" print("Executing: TRUNCATE keys")
conn.execute(text("TRUNCATE `keys`")) conn.execute(text("TRUNCATE `keys`"))
print "Bulk inserting the keys" print("Bulk inserting the keys")
op.bulk_insert(keys_table, new_keys) op.bulk_insert(keys_table, new_keys)
## Add type column to challenges ## Add type column to challenges
print "Adding type column to challenges" print("Adding type column to challenges")
op.add_column('challenges', sa.Column('type', sa.Integer(), nullable=True, default=0)) op.add_column('challenges', sa.Column('type', sa.Integer(), nullable=True, default=0))
## Set all NULLs to 0 ## Set all NULLs to 0
print "Setting all NULLs to 0" print("Setting all NULLs to 0")
conn.execute("UPDATE challenges set type=0 WHERE type IS NULL") conn.execute("UPDATE challenges set type=0 WHERE type IS NULL")
## Drop flags from challenges ## Drop flags from challenges
print "Dropping flags column from challenges" print("Dropping flags column from challenges")
op.drop_column('challenges', 'flags') op.drop_column('challenges', 'flags')
print "Finished" print("Finished")
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
print "Getting bind..." print("Getting bind...")
conn = op.get_bind() conn = op.get_bind()
print "Adding flags column back to challenges table" print("Adding flags column back to challenges table")
op.add_column('challenges', sa.Column('flags', sa.TEXT(), nullable=True)) op.add_column('challenges', sa.Column('flags', sa.TEXT(), nullable=True))
print "Dropping type column from challenges table" print("Dropping type column from challenges table")
op.drop_column('challenges', 'type') op.drop_column('challenges', 'type')
print "Executing: SELECT id, flags from challenges" print("Executing: SELECT id, flags from challenges")
res = conn.execute("SELECT id, flags from challenges") res = conn.execute("SELECT id, flags from challenges")
results = res.fetchall() results = res.fetchall()
print "There are {} results".format(len(results)) print("There are {} results".format(len(results)))
for chal_id in results: for chal_id in results:
new_keys = Keys.query.filter_by(chal=chal_id[0]).all() new_keys = Keys.query.filter_by(chal=chal_id[0]).all()
old_flags = [] old_flags = []
@@ -93,8 +93,8 @@ def downgrade():
flag_dict = {'flag': new_key.flag, 'type': new_key.key_type} flag_dict = {'flag': new_key.flag, 'type': new_key.key_type}
old_flags.append(flag_dict) old_flags.append(flag_dict)
old_flags =json.dumps(old_flags) old_flags =json.dumps(old_flags)
print "Updating challenge {} to insert {}".format(chal_id[0], flag_dict) print("Updating challenge {} to insert {}".format(chal_id[0], flag_dict))
conn.execute(text('UPDATE challenges SET flags=:flags WHERE id=:id'), id=chal_id[0], flags=old_flags) conn.execute(text('UPDATE challenges SET flags=:flags WHERE id=:id'), id=chal_id[0], flags=old_flags)
print "Finished" print("Finished")
# ### end Alembic commands ### # ### end Alembic commands ###