-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ blind copying. no touching on the file. simple copy files from temp…
…late directories to target path. related to #16
- Loading branch information
Showing
9 changed files
with
141 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ organisation: moremoban | |
author: C. W. | ||
contact: [email protected] | ||
license: MIT | ||
version: 0.1.3 | ||
current_version: 0.1.3 | ||
version: 0.1.4 | ||
current_version: 0.1.4 | ||
release: 0.1.3 | ||
branch: master | ||
command_line_interface: "moban" | ||
|
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,39 @@ | ||
import os | ||
import shutil | ||
|
||
import moban.reporter as reporter | ||
|
||
|
||
class Copier(object): | ||
def __init__(self, template_dirs): | ||
self.template_dirs = template_dirs | ||
self._count = 0 | ||
|
||
def copy_files(self, file_list): | ||
for dest_src_pair in file_list: | ||
for dest, src in dest_src_pair.items(): | ||
src_path = self._get_src_file(src) | ||
if src_path: | ||
reporter.report_copying(src_path, dest) | ||
shutil.copy(src_path, dest) | ||
self._count = self._count + 1 | ||
else: | ||
reporter.report_error_message( | ||
"{0} cannot be found".format(src)) | ||
|
||
def number_of_copied_files(self): | ||
return self._count | ||
|
||
def report(self): | ||
if self._count: | ||
reporter.report_copying_summary(self._count) | ||
else: | ||
reporter.report_no_action() | ||
|
||
def _get_src_file(self, src): | ||
for folder in self.template_dirs: | ||
path = os.path.join(folder, src) | ||
if os.path.exists(path): | ||
return path | ||
else: | ||
return None |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# Template by setupmobans | ||
#!/usr/bin/env python3 | ||
|
||
# Template by pypi-mobans | ||
import os | ||
import sys | ||
import codecs | ||
|
@@ -9,7 +11,7 @@ | |
|
||
NAME = 'moban' | ||
AUTHOR = 'C. W.' | ||
VERSION = '0.1.3' | ||
VERSION = '0.1.4' | ||
EMAIL = '[email protected]' | ||
LICENSE = 'MIT' | ||
ENTRY_POINTS = { | ||
|
@@ -20,7 +22,7 @@ | |
DESCRIPTION = ( | ||
'Yet another jinja2 cli command for static text generation' | ||
) | ||
URL = 'https://github.com/moremoban/moban' | ||
URL = 'https:///moremoban/moban' | ||
DOWNLOAD_URL = '%s/archive/0.1.3.tar.gz' % URL | ||
FILES = ['README.rst', 'CHANGELOG.rst'] | ||
KEYWORDS = [ | ||
|
@@ -30,8 +32,6 @@ | |
] | ||
|
||
CLASSIFIERS = [ | ||
'Topic :: Office/Business', | ||
'Topic :: Utilities', | ||
'Topic :: Software Development :: Libraries', | ||
'Programming Language :: Python', | ||
'Intended Audience :: Developers', | ||
|
@@ -134,7 +134,8 @@ def read_files(*files): | |
|
||
def read(afile): | ||
"""Read a file into setup""" | ||
with codecs.open(afile, 'r', 'utf-8') as opened_file: | ||
the_relative_file = os.path.join(HERE, afile) | ||
with codecs.open(the_relative_file, 'r', 'utf-8') as opened_file: | ||
content = filter_out_test_code(opened_file) | ||
content = "".join(list(content)) | ||
return content | ||
|
Empty file.
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,50 @@ | ||
import os | ||
from moban.copier import Copier | ||
from moban.mobanfile import handle_copy | ||
from nose.tools import eq_ | ||
from mock import patch | ||
|
||
|
||
class TestCopier: | ||
|
||
def setUp(self): | ||
self.patcher = patch("shutil.copy") | ||
self.fake_copy = self.patcher.start() | ||
|
||
def tearDown(self): | ||
self.patcher.stop() | ||
|
||
@patch("moban.reporter.report_copying") | ||
def test_copy_files(self, reporter): | ||
copier = Copier([os.path.join("tests", "fixtures")]) | ||
file_list = [{ | ||
"/tmp/test": "copier-test01.csv" | ||
}] | ||
copier.copy_files(file_list) | ||
self.fake_copy.assert_called() | ||
|
||
@patch("moban.reporter.report_error_message") | ||
def test_copy_files_file_not_found(self, reporter): | ||
copier = Copier([os.path.join("tests", "fixtures")]) | ||
file_list = [{ | ||
"/tmp/test": "copier-test-not-found.csv" | ||
}] | ||
copier.copy_files(file_list) | ||
reporter.assert_called_with( | ||
"copier-test-not-found.csv cannot be found") | ||
|
||
def test_number_of_files(self): | ||
copier = Copier([os.path.join("tests", "fixtures")]) | ||
file_list = [{ | ||
"/tmp/test": "copier-test01.csv" | ||
}] | ||
copier.copy_files(file_list) | ||
eq_(copier.number_of_copied_files(), 1) | ||
|
||
def test_handle_copy(self): | ||
tmpl_dirs = [os.path.join("tests", "fixtures")] | ||
copy_config = [{ | ||
"/tmp/test": "copier-test01.csv" | ||
}] | ||
count = handle_copy(tmpl_dirs, copy_config) | ||
eq_(count, 1) |