-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Victor Ferraz
committed
Feb 9, 2016
1 parent
ff11278
commit 514f11d
Showing
14 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from iprofile import texts | ||
from iprofile.core.decorators import icommand | ||
from iprofile.core.models import ICommand | ||
from iprofile.core.utils import get_ipython_path | ||
from iprofile.core.utils import get_profile_path | ||
import click | ||
import os | ||
|
||
|
||
@icommand(help=texts.HELP_LIST, short_help=texts.HELP_LIST) | ||
@click.option('--name-only', is_flag=True, help=texts.HELP_NAME_ONLY) | ||
class List(ICommand): | ||
|
||
def run(self, **options): | ||
try: | ||
profiles = filter( | ||
lambda x: os.path.isdir('{0}/{1}'.format(self.project_path, x)) | ||
and 'ipython_config.py' in os.listdir('{0}/{1}'.format( | ||
self.project_path, x)), os.listdir('iprofiles')) | ||
|
||
if len(profiles) == 0: | ||
self.no_profiles() | ||
return | ||
|
||
name_only = options.get('name_only', False) | ||
if not name_only: | ||
self.green(texts.LOG_QTD_PROFILES.format(len(profiles))) | ||
|
||
for profile in profiles: | ||
if name_only: | ||
click.echo(profile) | ||
else: | ||
ipython_path, _, _ = get_ipython_path(profile) | ||
click.echo('\nName: {}'.format(profile)) | ||
click.echo('IPython profile path:\t{}'.format( | ||
ipython_path)) | ||
click.echo('Project profile path:\t{}'.format( | ||
get_profile_path(profile))) | ||
except OSError: | ||
self.no_profiles() | ||
|
||
def no_profiles(self): | ||
self.red(texts.ERROR_NO_PROFILES_TO_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,6 @@ | |
LOG_QTD_CLEARED = ( | ||
"Successfully cleared {0} profiles." | ||
) | ||
LOG_QTD_PROFILES = ( | ||
"{0} profiles were found:" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from iprofile.cli import Create | ||
from iprofile.cli import Delete | ||
from iprofile.cli import List | ||
import shutil | ||
|
||
mock_options = { | ||
'name': 'test' | ||
} | ||
|
||
mock_options_1 = { | ||
'no_input': True | ||
} | ||
|
||
mock_options_2 = { | ||
'name_only': True | ||
} | ||
|
||
|
||
def test_run(): | ||
Create.run(mock_options) | ||
Create.run(mock_options) | ||
List.run({}) | ||
List.run(mock_options_2) | ||
Delete.run(mock_options_1) | ||
List.run({}) | ||
|
||
|
||
def test_no_iprofiles_folder(): | ||
shutil.move('iprofiles', 'iprofiles2') | ||
List.run({}) | ||
shutil.move('iprofiles2', 'iprofiles') |