Skip to content

Commit

Permalink
Port release wizard fixes
Browse files Browse the repository at this point in the history
Ported from:
- b2777781d37ee109b6c60acba95fe8c0478b2f36
- apache/solr#1020
  • Loading branch information
HoustonPutman committed Apr 19, 2023
1 parent af7769a commit d5a5e9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 94 deletions.
109 changes: 22 additions & 87 deletions hack/release/wizard/releaseWizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,16 @@ def get_title(self):
return "%s%s (%d/%d)" % (prefix, self.title, self.num_done(), self.num_applies())

def get_submenu(self):
menu = UpdatableConsoleMenu(title=self.title, subtitle=self.get_subtitle, prologue_text=self.get_description(),
screen=MyScreen())
menu = ConsoleMenu(title=self.title, subtitle=self.get_subtitle, prologue_text=self.get_description(),
clear_screen=False)
menu.exit_item = CustomExitItem("Return")
for todo in self.get_todos():
if todo.applies(state.release_type):
menu.append_item(todo.get_menu_item())
return menu

def get_menu_item(self):
item = UpdatableSubmenuItem(self.get_title, self.get_submenu())
item = SubmenuItem(self.get_title, self.get_submenu())
return item

def get_todos(self):
Expand Down Expand Up @@ -850,7 +850,7 @@ def display_and_confirm(self):
print("ERROR while executing todo %s (%s)" % (self.get_title(), e))

def get_menu_item(self):
return UpdatableFunctionItem(self.get_title, self.display_and_confirm)
return FunctionItem(self.get_title, self.display_and_confirm)

def clone(self):
clone = Todo(self.id, self.title, description=self.description)
Expand Down Expand Up @@ -1279,76 +1279,6 @@ def get_prologue_text(self):
def get_epilogue_text(self):
return self.epilogue_text() if callable(self.epilogue_text) else self.epilogue_text


class UpdatableSubmenuItem(SubmenuItem):
def __init__(self, text, submenu, menu=None, should_exit=False):
"""
:ivar ConsoleMenu self.submenu: The submenu to be opened when this item is selected
"""
super(SubmenuItem, self).__init__(text=text, menu=menu, should_exit=should_exit)

self.submenu = submenu
if menu:
self.get_submenu().parent = menu

def show(self, index):
return "%2d - %s" % (index + 1, self.get_text())

# Getters to get text in case method reference
def get_text(self):
return self.text() if callable(self.text) else self.text

def set_menu(self, menu):
"""
Sets the menu of this item.
Should be used instead of directly accessing the menu attribute for this class.
:param ConsoleMenu menu: the menu
"""
self.menu = menu
self.get_submenu().parent = menu

def action(self):
"""
This class overrides this method
"""
self.get_submenu().start()

def clean_up(self):
"""
This class overrides this method
"""
self.get_submenu().join()
self.menu.clear_screen()
self.menu.resume()

def get_return(self):
"""
:return: The returned value in the submenu
"""
return self.get_submenu().returned_value

def get_submenu(self):
"""
We unwrap the submenu variable in case it is a reference to a method that returns a submenu
"""
return self.submenu if not callable(self.submenu) else self.submenu()


class UpdatableFunctionItem(FunctionItem):
def show(self, index):
return "%2d - %s" % (index + 1, self.get_text())

# Getters to get text in case method reference
def get_text(self):
return self.text() if callable(self.text) else self.text


class MyScreen(Screen):
def clear(self):
return


class CustomExitItem(ExitItem):
def show(self, index):
return super(ExitItem, self).show(index)
Expand All @@ -1365,6 +1295,11 @@ def main():
print("Solr Operator releaseWizard %s" % getScriptVersion())
c = parse_config()

try:
ConsoleMenu(clear_screen=True)
except Exception as e:
sys.exit("You need to install 'consolemenu' package version 0.7.1 for the Wizard to function. Please run 'pip "
"install -r requirements.txt'")
if c.dry:
print("Entering dry-run mode where all commands will be echoed instead of executed")
dry_run = True
Expand Down Expand Up @@ -1411,18 +1346,18 @@ def main():

state.save()

main_menu = UpdatableConsoleMenu(title="Solr Operator ReleaseWizard",
main_menu = ConsoleMenu(title="Solr Operator ReleaseWizard",
subtitle=get_releasing_text,
prologue_text="Welcome to the release wizard. From here you can manage the process including creating new RCs. "
"All changes are persisted, so you can exit any time and continue later. Make sure to read the Help section.",
epilogue_text="® 2020 The Solr Operator project. Licensed under the Apache License 2.0\nScript version %s)" % getScriptVersion(),
screen=MyScreen())
clear_screen=False)

todo_menu = UpdatableConsoleMenu(title=get_releasing_text,
todo_menu = ConsoleMenu(title=get_releasing_text,
subtitle=get_subtitle,
prologue_text=None,
epilogue_text=None,
screen=MyScreen())
clear_screen=False)
todo_menu.exit_item = CustomExitItem("Return")

for todo_group in state.todo_groups:
Expand All @@ -1431,14 +1366,14 @@ def main():
menu_item.set_menu(todo_menu)
todo_menu.append_item(menu_item)

main_menu.append_item(UpdatableSubmenuItem(get_todo_menuitem_title, todo_menu, menu=main_menu))
main_menu.append_item(UpdatableFunctionItem(get_start_new_rc_menu_title, start_new_rc))
main_menu.append_item(UpdatableFunctionItem('Clear and restart current RC', state.clear_rc))
main_menu.append_item(UpdatableFunctionItem("Clear all state, restart the %s release" % state.release_version, reset_state))
main_menu.append_item(UpdatableFunctionItem('Start release for a different version', release_other_version))
main_menu.append_item(UpdatableFunctionItem('Generate Asciidoc guide for this release', generate_asciidoc))
# main_menu.append_item(UpdatableFunctionItem('Dump YAML', dump_yaml))
main_menu.append_item(UpdatableFunctionItem('Help', help))
main_menu.append_item(SubmenuItem(get_todo_menuitem_title, todo_menu, menu=main_menu))
main_menu.append_item(FunctionItem(get_start_new_rc_menu_title, start_new_rc))
main_menu.append_item(FunctionItem('Clear and restart current RC', state.clear_rc))
main_menu.append_item(FunctionItem("Clear all state, restart the %s release" % state.release_version, reset_state))
main_menu.append_item(FunctionItem('Start release for a different version', release_other_version))
main_menu.append_item(FunctionItem('Generate Asciidoc guide for this release', generate_asciidoc))
# main_menu.append_item(FunctionItem('Dump YAML', dump_yaml))
main_menu.append_item(FunctionItem('Help', help))

main_menu.show()

Expand Down Expand Up @@ -1964,7 +1899,7 @@ def create_ical(todo):
sundays = {(today + timedelta(days=x)): 'Sunday' for x in range(10) if (today + timedelta(days=x)).weekday() == 6}
y = datetime.utcnow().year
years = [y, y+1]
non_working = holidays.CA(years=years) + holidays.US(years=years) + holidays.England(years=years) \
non_working = holidays.CA(years=years) + holidays.US(years=years) + holidays.UK(years=years) \
+ holidays.DE(years=years) + holidays.NO(years=years) + holidays.IND(years=years) + holidays.RU(years=years)


Expand Down
14 changes: 7 additions & 7 deletions hack/release/wizard/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
six>=1.11.0
Jinja2>=2.10.1
PyYAML>=5.1
holidays>=0.9.10
ics>=0.4
console-menu>=0.5.1
PyGithub
six~=1.16.0
Jinja2~=3.1.1
PyYAML~=6.0
holidays~=0.16
ics~=0.7.2
console-menu~=0.7.1
PyGithub~=1.56

0 comments on commit d5a5e9f

Please sign in to comment.