Skip to content

Commit

Permalink
Improve init template
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Jun 14, 2016
1 parent 9f91a46 commit e2d3206
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
16 changes: 12 additions & 4 deletions manage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ def load_manage_dict(filename=None):
elif os.path.exists(HIDDEN_MANAGE_FILE):
manage_filename = HIDDEN_MANAGE_FILE
else:
default_manage_dict['shell']['banner']['message'] = (
"WARNING: This is not a managed project\n"
"\tPlease `exit()` and \n"
"\trun `$ manage init`\n"
"\tand edit `manage.yml` file with desired options"
)
default_manage_dict['shell']['auto_import']['display'] = False
MANAGE_DICT.update(default_manage_dict)

if manage_filename:
with open(manage_filename) as manage_file:
MANAGE_DICT.update(yaml.load(manage_file))

return MANAGE_DICT


Expand Down Expand Up @@ -83,7 +89,8 @@ def init(config, banner, hidden, backup):

with open(manage_file, 'w') as output:
data = default_manage_dict
data['shell']['banner']['message'] = banner
if banner:
data['shell']['banner']['message'] = banner
output.write(yaml.dump(data, default_flow_style=False))


Expand All @@ -110,7 +117,7 @@ def shell(config, ipython, ptpython):
msgs.append(
manage_dict['shell']['banner']['message'].format(**manage_dict)
)
if manage_dict['shell']['auto_import']['display']:
if auto_imported and manage_dict['shell']['auto_import']['display']:
auto_imported_names = [
key for key in auto_imported.keys()
if key not in ['__builtins__', 'builtins']
Expand Down Expand Up @@ -170,7 +177,8 @@ def main():
cli.help = MANAGE_DICT.get(
'help_text', '{project_name} Interactive shell!'
).format(**MANAGE_DICT)
cli.add_command(foo, name='bla')
# TODO: Load commands
# cli.add_command(foo, name='bla')
return cli()


Expand Down
15 changes: 9 additions & 6 deletions manage/template.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
default_manage_dict = {
'project_name': 'Project',
'help_text': "This is the {project_name} interactive shell",
'shell': { # Preferences for 'manage shell'
'banner': { # Banner is the message printed on top of console
'enabled': True, # It can be disabled
'message': 'Hello World!' # Here it goes the message
# Here it goes the message
'message': "Manage Interactive Shell! edit your `manage.yml`",
},
'auto_import': { # Objects to be auto imported to shell context
'display': True, # Weather to print all a list of all objects
'objects': {

}
}
}
'objects': {}
},
'readline_enabled': True,
'init_script': 'print("Starting interactive shell!")'
},
'commands': []
}

0 comments on commit e2d3206

Please sign in to comment.