Skip to content
Browse files

Make scripts to be generated in the project root instead of bin/

  • Loading branch information...
1 parent 51f26bf commit 9c9310a3e9dd9de6cde56a6696f3f2c6b2dd8652 @andreafrancia committed Nov 5, 2012
Showing with 31 additions and 35 deletions.
  1. +10 −2 .gitignore
  2. +13 −19 setup.py
  3. +8 −14 unit_tests/test_make_script.py
View
12 .gitignore
@@ -4,8 +4,16 @@
.coverage
.DS_Store
.local/
-.svn
-/bin/
+
+# generated executables
+/restore-trash
+/trash-empty
+/trash-list
+/trash-put
+/trash-rm
+/trash
+
+# other things
/build/
/command-test/sandbox/
/command-test/test-volume.img
View
32 setup.py
@@ -6,12 +6,12 @@
def main():
sys.path.append('.')
from trashcli import trash
- bin_dir.add_script('trash' , 'trashcli.put' , 'main')
- bin_dir.add_script('trash-put' , 'trashcli.put' , 'main')
- bin_dir.add_script('trash-list' , 'trashcli.cmds', 'list')
- bin_dir.add_script('restore-trash', 'trashcli.cmds', 'restore')
- bin_dir.add_script('trash-empty' , 'trashcli.cmds', 'empty')
- bin_dir.add_script('trash-rm' , 'trashcli.rm' , 'main')
+ scripts.add_script('trash' , 'trashcli.put' , 'main')
+ scripts.add_script('trash-put' , 'trashcli.put' , 'main')
+ scripts.add_script('trash-list' , 'trashcli.cmds', 'list')
+ scripts.add_script('restore-trash', 'trashcli.cmds', 'restore')
+ scripts.add_script('trash-empty' , 'trashcli.cmds', 'empty')
+ scripts.add_script('trash-rm' , 'trashcli.rm' , 'main')
setup(
name = 'trash-cli' , version = trash.version ,
author = 'Andrea Francia' , author_email = 'andrea@andreafrancia.it' ,
@@ -20,7 +20,7 @@ def main():
long_description = file("README.rst").read(),
license = 'GPL v2',
packages = ['trashcli'],
- scripts = bin_dir.created_scripts,
+ scripts = scripts.created_scripts,
data_files = [('share/man/man1', ['man/man1/trash-empty.1',
'man/man1/trash-list.1',
'man/man1/restore-trash.1',
@@ -29,11 +29,10 @@ def main():
)
from textwrap import dedent
-class BinDir:
- def __init__(self, write_file, make_file_executable, make_dir):
+class Scripts:
+ def __init__(self, write_file, make_file_executable):
self.write_file = write_file
self.make_file_executable = make_file_executable
- self.make_dir = make_dir
self.created_scripts = []
def add_script(self, name, module, main_function):
script_contents = dedent("""\
@@ -43,22 +42,17 @@ def add_script(self, name, module, main_function):
from %(module)s import %(main_function)s as main
sys.exit(main())
""") % locals()
- self.make_dir('bin')
- executable = 'bin/' + name
- self.write_file(executable, script_contents)
- self.make_file_executable(executable)
- self.created_scripts.append(executable)
+ self.write_file(name, script_contents)
+ self.make_file_executable(name)
+ self.created_scripts.append(name)
import os,stat
def make_file_executable(path):
os.chmod(path, os.stat(path).st_mode | stat.S_IXUSR)
def write_file(name, contents):
file(name, 'w').write(contents)
-def make_dir(path):
- if not os.path.isdir(path):
- os.mkdir(path)
-bin_dir = BinDir(write_file, make_file_executable, make_dir)
+scripts = Scripts(write_file, make_file_executable)
if __name__ == '__main__':
main()
View
22 unit_tests/test_make_script.py
@@ -2,32 +2,27 @@
from nose.tools import assert_equals
import mock
from mock import Mock
-from setup import BinDir
+from setup import Scripts
class TestMakeScript:
def setUp(self):
self.make_file_executable = Mock()
self.write_file = Mock()
- self.make_dir = Mock()
def capture(name, contents):
self.name = name
self.contents = contents
self.write_file.side_effect = capture
- bindir = BinDir(
+ bindir = Scripts(
make_file_executable = self.make_file_executable,
- write_file = self.write_file,
- make_dir = self.make_dir)
+ write_file = self.write_file)
bindir.add_script('trash-put', 'trashcli.cmds', 'put')
- def test_should_make_bin_dir(self):
- self.make_dir.assert_called_with('bin')
-
def test_should_set_executable_permission(self):
- self.make_file_executable.assert_called_with('bin/trash-put')
+ self.make_file_executable.assert_called_with('trash-put')
def test_should_write_the_script(self):
- self.write_file.assert_called_with( 'bin/trash-put', mock.ANY)
+ self.write_file.assert_called_with( 'trash-put', mock.ANY)
def test_the_script_should_call_the_right_function_from_the_right_module(self):
args, kwargs = self.write_file.call_args
@@ -46,14 +41,13 @@ def test_the_script_should_call_the_right_function_from_the_right_module(self):
class TestListOfCreatedScripts:
def setUp(self):
- self.bindir = BinDir(
+ self.bindir = Scripts(
make_file_executable = Mock(),
- write_file = Mock(),
- make_dir = Mock())
+ write_file = Mock())
def test_is_empty_on_start_up(self):
assert_equals(self.bindir.created_scripts, [])
def test_collect_added_script(self):
self.bindir.add_script('foo-command', 'foo-module', 'main')
- assert_equals(self.bindir.created_scripts, ['bin/foo-command'])
+ assert_equals(self.bindir.created_scripts, ['foo-command'])

0 comments on commit 9c9310a

Please sign in to comment.
Something went wrong with that request. Please try again.