Skip to content

Commit

Permalink
Small changes on structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Ferraz committed Feb 14, 2016
1 parent 298559a commit 90ae84c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion iprofile/cli/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def clear_all(self):
if cleared == 0:
self.red(texts.ERROR_NO_PROFILES_TO_CLEAR)
else:
click.echo(texts.LOG_QTD_CLEARED.format(
click.echo(texts.LOG_QTT_CLEARED.format(
cleared, 's' if cleared != 1 else ''))
return names
2 changes: 1 addition & 1 deletion iprofile/cli/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run(self, **options):
if deleted == 0:
self.red(texts.ERROR_NO_PROFILES_TO_DELETE)
else:
click.echo(texts.LOG_QTD_DELETED.format(
click.echo(texts.LOG_QTT_DELETED.format(
deleted, 's' if deleted != 1 else ''))
elif names:
self.run_for_profile(Profile(names, self.global_config))
Expand Down
4 changes: 3 additions & 1 deletion iprofile/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from iprofile import texts
from iprofile.core.decorators import icommand
from iprofile.core.utils import GLOBAL_SETTINGS_FILE
from iprofile.models import ICommand
from slugify import slugify
import click
Expand Down Expand Up @@ -36,7 +37,8 @@ def run(self, **options):
self.global_config.save()

self.green(texts.LOG_IPROFILE_INITIALIZED.format(abspath))
click.echo(texts.LOG_IPROFILE_YML.format(os.getcwd(), action))
click.echo(texts.LOG_IPROFILE_YML.format(
os.getcwd(), action, GLOBAL_SETTINGS_FILE))

except OSError:
self.red(texts.ERROR_INIT_PATH_EXISTS.format(abspath))
4 changes: 2 additions & 2 deletions iprofile/cli/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run(self, **options):

show_only = options.get('show_only', None)
if not show_only:
self.green(texts.LOG_QTD_PROFILES.format(
self.green(texts.LOG_QTT_PROFILES.format(
qtd_profiles,
's' if qtd_profiles != 1 else '',
'were' if qtd_profiles != 1 else 'was'
Expand All @@ -35,7 +35,7 @@ def run(self, **options):
for profile_name in profiles:
profile = Profile(profile_name, self.global_config)
if show_only == 'names':
click.echo(profile_name)
click.echo(profile.name)
elif show_only == 'paths':
click.echo(profile.ipython_locate())
else:
Expand Down
6 changes: 5 additions & 1 deletion iprofile/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import click
import os

PROFILE_SETTINGS_FILE = 'settings.yml'
GLOBAL_SETTINGS_FILE = 'iprofile.yml'


def get_ipython_name(profile_name, config):
return '{0}_{1}'.format(
Expand Down Expand Up @@ -33,7 +36,8 @@ def list_profiles(project_path):
return [
x for x in os.listdir(project_path)
if os.path.isdir('{0}/{1}'.format(project_path, x)) and
'settings.yml' in os.listdir('{0}/{1}'.format(project_path, x))
PROFILE_SETTINGS_FILE in os.listdir(
'{0}/{1}'.format(project_path, x))
]
return []

Expand Down
6 changes: 4 additions & 2 deletions iprofile/models/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

from iprofile.core.utils import PROFILE_SETTINGS_FILE
from iprofile.core.utils import GLOBAL_SETTINGS_FILE
import yaml
import os
import IPython
Expand All @@ -8,7 +10,7 @@
class GlobalConfig(object):

def __init__(self):
self.filepath = os.path.join(os.getcwd(), 'iprofile.yml')
self.filepath = os.path.join(os.getcwd(), GLOBAL_SETTINGS_FILE)
self._config = {}

if not os.path.isfile(self.filepath):
Expand Down Expand Up @@ -58,7 +60,7 @@ def save(self):
class ProfileConfig(GlobalConfig):

def __init__(self, path, profile):
self.filepath = os.path.join(path, profile, 'settings.yml')
self.filepath = os.path.join(path, profile, PROFILE_SETTINGS_FILE)
self._config = {}

def read(self):
Expand Down
3 changes: 2 additions & 1 deletion iprofile/models/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from slugify import slugify
from iprofile.core.utils import get_ipython_name
from iprofile.core.utils import get_user_home
from iprofile.core.utils import PROFILE_SETTINGS_FILE
from iprofile.models import ProfileConfig
import IPython
import os
Expand Down Expand Up @@ -31,7 +32,7 @@ def __init__(self, name, config, **kwargs):

self._path = {
'profile': profile_path,
'settings': os.path.join(profile_path, 'settings.yml'),
'settings': os.path.join(profile_path, PROFILE_SETTINGS_FILE),
'startup': os.path.join(profile_path, 'startup'),
'config': os.path.join(profile_path, 'ipython_config.py'),
}
Expand Down
8 changes: 4 additions & 4 deletions iprofile/texts/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
LOG_ACTIVE_PROFILE = (
"Active profile: "
)
LOG_QTD_DELETED = (
LOG_QTT_DELETED = (
"Successfully deleted {0} profile{1}."
)
LOG_QTD_CLEARED = (
LOG_QTT_CLEARED = (
"Successfully cleared {0} profile{1}."
)
LOG_QTD_PROFILES = (
LOG_QTT_PROFILES = (
"{0} profile{1} {2} found:"
)
LOG_IPROFILE_INITIALIZED = (
"Successfully initialized IProfile at '{0}'."
)
LOG_IPROFILE_YML = "{1} config file at '{0}/iprofile.yml'."
LOG_IPROFILE_YML = "{1} config file at '{0}/{2}'."
3 changes: 2 additions & 1 deletion tests/test_cli/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from iprofile.cli import Init
from iprofile.core.utils import makedirs
from iprofile.core.utils import GLOBAL_SETTINGS_FILE
import os
import shutil

Expand All @@ -17,7 +18,7 @@ def test_run():

def test_no_profile_yml():
try:
os.remove(os.path.join(os.getcwd(), 'iprofile.yml'))
os.remove(os.path.join(os.getcwd(), GLOBAL_SETTINGS_FILE))
except OSError:
pass
shutil.rmtree('iprofiles', ignore_errors=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-

from iprofile.core.utils import GLOBAL_SETTINGS_FILE
from iprofile.models import ICommand
from iprofile.models import GlobalConfig
from iprofile.models import Profile
import pytest
import os

Expand All @@ -14,7 +14,7 @@ def test_run_not_implemented_error():

def test_iprofiles_yml_does_not_exist():
try:
os.remove('iprofile.yml')
os.remove(GLOBAL_SETTINGS_FILE)
except OSError:
pass
GlobalConfig()

0 comments on commit 90ae84c

Please sign in to comment.