Skip to content

Commit

Permalink
First step in changing to shell module.
Browse files Browse the repository at this point in the history
  • Loading branch information
starcraftman committed Jun 2, 2016
1 parent 8308a4b commit 51e6e20
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pakit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from __future__ import absolute_import

from pakit.recipe import Recipe
from pakit.shell import Archive, Dummy, Git, Hg
from pakshell.shell import Archive, Dummy, Git, Hg

__all__ = ['Archive', 'Dummy', 'Git', 'Hg', 'Recipe']

Expand Down
4 changes: 2 additions & 2 deletions pakit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import pakit.conf
import pakit.recipe
import pakit.shell
from pakit import __version__
from pakit.conf import Config, InstallDB
from pakit.exc import PakitError, PakitDBError
Expand All @@ -22,6 +21,7 @@
InstallTask, RemoveTask, UpdateTask, ListInstalled, ListAvailable,
DisplayTask, RelinkRecipes, SearchTask, CreateConfig, PurgeTask
)
from pakshell.shell import link_man_pages


PLOG = logging.getLogger('pakit').info
Expand Down Expand Up @@ -208,7 +208,7 @@ def global_init(config_file):
recipe_db.index(path)
pakit.recipe.RDB = recipe_db

pakit.shell.link_man_pages(config.path_to('link'))
link_man_pages(config.path_to('link'))
environment_check(config)

return config
Expand Down
4 changes: 2 additions & 2 deletions pakit/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from pakit.conf import RecipeURIDB
from pakit.exc import PakitDBError, PakitError
from pakit.shell import Command, vcs_factory
from pakshell.shell import Command, vcs_factory


PLOG = logging.getLogger('pakit').info
Expand Down Expand Up @@ -225,7 +225,7 @@ def repo_name(self):

def cmd(self, cmd, **kwargs):
"""
Wrapper around pakit.shell.Command. Behaves the same except:
Wrapper around pakt.shell.Command. Behaves the same except:
- Expand all dictionary markers in *cmd* against *self.opts*.
Arg *cmd* may be a string or a list of strings.
Expand Down
2 changes: 1 addition & 1 deletion pakit/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import pakit.conf
import pakit.recipe
from pakit.exc import PakitCmdError, PakitLinkError
from pakit.shell import (
from pakshell.shell import (
Command, walk_and_link, walk_and_unlink, walk_and_unlink_all,
write_config, unlink_man_pages, user_input, cd_and_call
)
Expand Down
Empty file added pakshell/__init__.py
Empty file.
6 changes: 4 additions & 2 deletions pakit/shell.py → pakshell/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ def link_man_pages(link_dir):
"""
Silently links project man pages into link dir.
"""
src = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'extra')
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
src = os.path.join(root, 'pakit', 'extra')
dst = os.path.join(link_dir, 'share', 'man', 'man1')
try:
os.makedirs(dst)
Expand All @@ -408,7 +409,8 @@ def unlink_man_pages(link_dir):
"""
Unlink all man pages from the link directory.
"""
src = os.path.join(os.path.dirname(__file__), 'extra')
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
src = os.path.join(root, 'pakit', 'extra')
dst = os.path.join(link_dir, 'share', 'man', 'man1')

for page in glob.glob(os.path.join(src, '*.1')):
Expand Down
17 changes: 8 additions & 9 deletions tests/test_shell.py → tests/test_pakshell_shell.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Test pakit.shell
Test pakshell.shell
"""
from __future__ import absolute_import, print_function
import os
Expand All @@ -10,8 +10,7 @@
from pakit.exc import (
PakitError, PakitCmdError, PakitCmdTimeout, PakitLinkError
)
import pakit.shell
from pakit.shell import (
from pakshell.shell import (
Archive, Dummy, Git, Hg, Command, hash_archive,
common_suffix, cmd_cleanup, get_extract_func, extract_tar_gz,
walk_and_link, walk_and_unlink, walk_and_unlink_all, vcs_factory,
Expand All @@ -27,7 +26,7 @@ def test_reach_github():


@pytest.mark.skip(reason='TODO: to be reviewed')
@mock.patch('pakit.shell.Command')
@mock.patch('pakshell.shell.Command')
def test_reach_github_fails(mock_cmd):
mock_cmd.side_effect = PakitError('Fail.')
assert not reach_github()
Expand Down Expand Up @@ -129,7 +128,7 @@ def test_hash_archive_sha256():
os.remove(arc.arc_file)


@mock.patch('pakit.shell.shutil')
@mock.patch('pakshell.shell.shutil')
def test_cmd_cleanup(mock_shutil):
cmd_cleanup()
mock_shutil.rmtree.assert_called_with(pakit.conf.TMP_DIR)
Expand Down Expand Up @@ -286,7 +285,7 @@ def __test_ext(self, ext):
def test_rar(self):
self.__test_ext('rar')

@mock.patch('pakit.shell.subprocess')
@mock.patch('pakshell.shell.subprocess')
def test_rar_unavailable(self, mock_sub):
mock_sub.side_effect = PakitCmdError('No cmd.')
with pytest.raises(PakitCmdError):
Expand Down Expand Up @@ -316,7 +315,7 @@ def test_tar_gz(self):
def test_tar_xz(self):
self.__test_ext('tar.xz')

@mock.patch('pakit.shell.subprocess')
@mock.patch('pakshell.shell.subprocess')
def test_tar_xz_unavailable(self, mock_sub):
mock_sub.side_effect = PakitCmdError('No cmd.')
with pytest.raises(PakitCmdError):
Expand All @@ -328,7 +327,7 @@ def test_zip(self):
def test_7z(self):
self.__test_ext('7z')

@mock.patch('pakit.shell.subprocess')
@mock.patch('pakshell.shell.subprocess')
def test_7z_unavailable(self, mock_sub):
mock_sub.side_effect = PakitCmdError('No cmd.')
with pytest.raises(PakitCmdError):
Expand All @@ -350,7 +349,7 @@ def test__with__(self):
with self.dummy:
assert self.dummy.ready

@mock.patch('pakit.shell.Dummy.clean')
@mock.patch('pakshell.shell.Dummy.clean')
def test__with__fails(self, _):
os.makedirs(self.dummy.target)
with pytest.raises(PakitError):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_cwd_arg(self):
except OSError:
pass

@mock.patch('pakit.shell.Command.wait')
@mock.patch('pakshell.shell.Command.wait')
def test_cmd_timeout_arg(self, mock_cmd):
self.recipe.cmd('ls', timeout=1)
mock_cmd.assert_called_with(1)
Expand Down

0 comments on commit 51e6e20

Please sign in to comment.