| |
@@ -0,0 +1,83 @@
|
| |
+ """Event Dates
|
| |
+
|
| |
+ Revision ID: 31a71e8c7dfa
|
| |
+ Revises: 1e0fb82777af
|
| |
+ Create Date: 2020-11-19 09:50:46.323162
|
| |
+
|
| |
+ """
|
| |
+
|
| |
+ import requests
|
| |
+ import re
|
| |
+ import datetime
|
| |
+
|
| |
+ from sqlalchemy.orm import sessionmaker
|
| |
+
|
| |
+ from testdays.models.testday import Event
|
| |
+ from testdays.lib import wiki
|
| |
+
|
| |
+ Session = sessionmaker()
|
| |
+
|
| |
+ # revision identifiers, used by Alembic.
|
| |
+ revision = '31a71e8c7dfa'
|
| |
+ down_revision = '1e0fb82777af'
|
| |
+ branch_labels = None
|
| |
+ depends_on = None
|
| |
+
|
| |
+ from alembic import op
|
| |
+ import sqlalchemy as sa
|
| |
+
|
| |
+ def process_past_event_dates():
|
| |
+
|
| |
+ connection = op.get_bind()
|
| |
+ session = Session(bind=connection)
|
| |
+ events = session.query(Event).order_by(Event.created_at.desc())
|
| |
+ for event in events:
|
| |
+ print("Processing TD %s" % event.name)
|
| |
+
|
| |
+ # Some testdays urls are redirect, follow and clean target
|
| |
+ # Eg. http://fedoraproject.org/wiki/Test_Day:F33_SwapOnZRAM
|
| |
+ # to
|
| |
+ # https://fedoraproject.org/wiki/Test_Day:2020-07-06_Swap_on_ZRAM?rd=Test_Day:F33_SwapOnZRAM
|
| |
+ r = requests.get(event.testday_url)
|
| |
+
|
| |
+ # Urls after redirects contain unnecessary ?rd=someting parameter, our code would crash on that, purge it
|
| |
+ # Eg. https://fedoraproject.org/wiki/Test_Day:2020-07-06_Swap_on_ZRAM?rd=Test_Day:F33_SwapOnZRAM
|
| |
+ # to https://fedoraproject.org/wiki/Test_Day:2020-07-06_Swap_on_ZRAM
|
| |
+ to_clean = re.findall(r'\?rd.*', r.url)
|
| |
+ if len(to_clean) == 1:
|
| |
+ cleaned_url = r.url.replace(re.findall(r'\?rd.*', r.url)[0], "")
|
| |
+ else:
|
| |
+ cleaned_url = r.url
|
| |
+
|
| |
+ # Some more cleaning
|
| |
+ # https://fedoraproject.org/w/index.php?title=Test_Day:2018-04-11_Cloud-Atomic_Testday
|
| |
+ # to
|
| |
+ # https://fedoraproject.org/Wiki/Test_Day:2018-04-11_Cloud-Atomic_Testday
|
| |
+ cleaned_url = cleaned_url.replace("fedoraproject.org/w/index.php?title=", "fedoraproject.org/wiki/")
|
| |
+
|
| |
+ # Parse dates
|
| |
+ start, end = wiki.get_td_dates(cleaned_url)
|
| |
+
|
| |
+ if start == datetime.datetime(1900, 1, 1, 0, 0):
|
| |
+ print("Could not parse event's date, using default")
|
| |
+
|
| |
+ event.testday_start = start
|
| |
+ event.testday_end = end
|
| |
+ session.commit()
|
| |
+
|
| |
+ def upgrade():
|
| |
+ # ### commands auto generated by Alembic - please adjust! ###
|
| |
+ op.add_column('event', sa.Column('testday_end', sa.DateTime(), nullable=True))
|
| |
+ op.add_column('event', sa.Column('testday_start', sa.DateTime(), nullable=True))
|
| |
+ # ### end Alembic commands ###
|
| |
+
|
| |
+ # Process data changes
|
| |
+ process_past_event_dates()
|
| |
+
|
| |
+
|
| |
+
|
| |
+ def downgrade():
|
| |
+ # ### commands auto generated by Alembic - please adjust! ###
|
| |
+ op.drop_column('event', 'testday_start')
|
| |
+ op.drop_column('event', 'testday_end')
|
| |
+ # ### end Alembic commands ###
|
| |
This will be split into multiple Pull Requests.
In the first one, the aim is to add functions to parse testday date ranges from wiki, update db models, wire the parsing to testday creation (not tested yet) and wire up code to update past testdays (not tested yet) .
And finally, I'll change the UI (with other tweaks) to distinguish active and past testdays.