Skip to content
This repository has been archived by the owner on Jan 19, 2018. It is now read-only.

Adds -a option to genanswers to designate where to put answers.conf #638

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion atomicapp/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def print_app_location(app_path):

def cli_genanswers(args):
argdict = args.__dict__
location = argdict['answers']
Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't think we need to do this here. What do you think about just passing it in with the rest of the args and do it inside the function in main.py ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was following similar to how we do:

destination = argdict['destination'] 

Should we not follow this convention / convert to do this later in main.py?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you were trying to do now. this seems reasonable. +1

nm = NuleculeManager(app_spec=argdict['app_spec'],
destination='none')
nm.genanswers(**argdict)
nm.genanswers(location=location, **argdict)
Utils.rm_dir(nm.app_path) # clean up files
sys.exit(0)

Expand Down Expand Up @@ -350,6 +351,11 @@ def create_parser(self):
# === "genanswers" SUBPARSER ===
gena_subparser = toplevel_subparsers.add_parser(
"genanswers", parents=[globals_parser])
gena_subparser.add_argument(
"-a",
"--answers",
dest="answers",
help="Path to %s" % ANSWERS_FILE)
gena_subparser.add_argument(
"app_spec",
nargs='?',
Expand Down
15 changes: 12 additions & 3 deletions atomicapp/nulecule/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def unpack(self, update=False,
return Nulecule.load_from_path(
self.app_path, dryrun=dryrun, config=config)

def genanswers(self, dryrun=False, answers_format=None, **kwargs):
def genanswers(self, dryrun=False, answers_format=None, location=None, **kwargs):
"""
Renders artifacts and then generates an answer file. Finally
copies answer file to the current working directory.
Expand All @@ -147,10 +147,19 @@ def genanswers(self, dryrun=False, answers_format=None, **kwargs):
self.answers_format = answers_format or ANSWERS_FILE_SAMPLE_FORMAT

# Check to make sure an answers.conf file doesn't exist already
answers_file = os.path.join(os.getcwd(), ANSWERS_FILE)
if location is None:
answers_file = os.path.join(os.getcwd(), ANSWERS_FILE)
else:
answers_file = os.path.join(location, ANSWERS_FILE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Double sigh.. problems like this make me want to retire. Ok we need to handle this for both the "in container" and "native" cases. That means if we are inside a container and the path is absolute then we need to translate the path like is done here: https://github.com/projectatomic/atomicapp/blob/master/atomicapp/nulecule/main.py#L72

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm a bit confused in regards to self.app_path.

So if inContainer() comes back as true, we'd use the /host/ path, correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

sigh.. another reason to retire :)

The link i used was based on master.. which moved since I pasted the link.. lets try using a link where the content won't move:

if os.path.isabs(app_spec):

basically if the path is absolute then we want to convert to the equivalent path inside the container. we are using the getRoot() function for this in other places.


if os.path.exists(answers_file):
raise NuleculeException(
"Can't generate answers.conf over existing file")
"Can't generate %s over existing file" % answers_file)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be better to have the file at the end after a colon:

"Can't generate answers. File exists: %s" % answers_file


answers_folder = os.path.dirname(answers_file)
if not os.path.isdir(answers_folder):
raise NuleculeException(
"Directory %s does not exist." % answers_folder)

# Call unpack to get the app code
self.nulecule = self.unpack(update=False, dryrun=dryrun, config=self.answers)
Expand Down