Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 45 additions & 43 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,42 @@ def progressCallback(x):
doCleanup(answers['cleanup'])
del answers['cleanup']

def determineRepositories(answers, answers_pristine, main_repositories, update_repositories):
def add_repos(main_repositories, update_repositories, repos):
"""Add repositories to the appropriate list, ensuring no duplicates,
that the main repository is at the beginning, and that the order of the
rest is maintained."""

for repo in repos:
if isinstance(repo, repository.UpdateYumRepository):
repo_list = update_repositories
else:
repo_list = main_repositories

if repo not in repo_list:
if repo.identifier() == MAIN_REPOSITORY_NAME:
repo_list.insert(0, repo)
else:
repo_list.append(repo)

# A list of sources coming from the answerfile
if 'sources' in answers_pristine:
for i in answers_pristine['sources']:
repos = repository.repositoriesFromDefinition(i['media'], i['address'])
add_repos(main_repositories, update_repositories, repos)

# A single source coming from an interactive install
if 'source-media' in answers_pristine and 'source-address' in answers_pristine:
repos = repository.repositoriesFromDefinition(answers_pristine['source-media'], answers_pristine['source-address'])
add_repos(main_repositories, update_repositories, repos)

for media, address in answers_pristine['extra-repos']:
repos = repository.repositoriesFromDefinition(media, address)
add_repos(main_repositories, update_repositories, repos)

if not main_repositories or main_repositories[0].identifier() != MAIN_REPOSITORY_NAME:
raise RuntimeError("No main repository found")

def performInstallation(answers, ui_package, interactive):
logger.log("INPUT ANSWERS DICTIONARY:")
prettyLogAnswers(answers)
Expand Down Expand Up @@ -352,9 +388,17 @@ def performInstallation(answers, ui_package, interactive):
assert answers['net-admin-interface'].startswith("eth")
answers['net-admin-bridge'] = "xenbr%s" % answers['net-admin-interface'][3:]

# A list needs to be used rather than a set since the order of updates is
# important. However, since the same repository might exist in multiple
# locations or the same location might be listed multiple times, care is
# needed to ensure that there are no duplicates.
main_repositories = []
update_repositories = []
answers_pristine = answers.copy()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need answers_pristine? At this point it is identical to answers and determineRepositories doesn't edit them (simply queries the contents and updates the lists by argument)
Seems like a good opportunity to simplify the extracted method

determineRepositories(answers, answers_pristine, main_repositories, update_repositories)

# perform installation:
prep_seq = getPrepSequence(answers, interactive)
answers_pristine = answers.copy()
executeSequence(prep_seq, "Preparing for installation...", answers, ui_package, False)

# install from main repositories:
Expand All @@ -368,48 +412,6 @@ def handleRepos(repos, ans):

answers['installed-repos'] = {}

# A list needs to be used rather than a set since the order of updates is
# important. However, since the same repository might exist in multiple
# locations or the same location might be listed multiple times, care is
# needed to ensure that there are no duplicates.
main_repositories = []
update_repositories = []

def add_repos(main_repositories, update_repositories, repos):
"""Add repositories to the appropriate list, ensuring no duplicates,
that the main repository is at the beginning, and that the order of the
rest is maintained."""

for repo in repos:
if isinstance(repo, repository.UpdateYumRepository):
repo_list = update_repositories
else:
repo_list = main_repositories

if repo not in repo_list:
if repo.identifier() == MAIN_REPOSITORY_NAME:
repo_list.insert(0, repo)
else:
repo_list.append(repo)

# A list of sources coming from the answerfile
if 'sources' in answers_pristine:
for i in answers_pristine['sources']:
repos = repository.repositoriesFromDefinition(i['media'], i['address'])
add_repos(main_repositories, update_repositories, repos)

# A single source coming from an interactive install
if 'source-media' in answers_pristine and 'source-address' in answers_pristine:
repos = repository.repositoriesFromDefinition(answers_pristine['source-media'], answers_pristine['source-address'])
add_repos(main_repositories, update_repositories, repos)

for media, address in answers_pristine['extra-repos']:
repos = repository.repositoriesFromDefinition(media, address)
add_repos(main_repositories, update_repositories, repos)

if not main_repositories or main_repositories[0].identifier() != MAIN_REPOSITORY_NAME:
raise RuntimeError("No main repository found")

handleMainRepos(main_repositories, answers)
if update_repositories:
handleRepos(update_repositories, answers)
Expand Down