-
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
Showing
5 changed files
with
128 additions
and
83 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
* text eol=lf |
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 +1,33 @@ | ||
{ "folders": [ { "path": ".", "file_exclude_patterns": [ "*.pyc", "*.sublime-workspace", "*.sublime-project", ".gitignore" ], "folder_exclude_patterns": [ "build", "*.egg-info", "dist" ] } ], "settings": { "font_size": 10, "tab_size": 4, "indent_spaces": true, "rulers": [120], "translate_tabs_to_spaces": true, "trim_automatic_white_space": true, "bold_folder_labels": true, "ensure_newline_at_eof_on_save": true } } | ||
{ | ||
"folders": | ||
[ | ||
{ | ||
"path": ".", | ||
"file_exclude_patterns": | ||
[ | ||
"*.pyc", | ||
"*.sublime-workspace", | ||
"*.sublime-project", | ||
".gitignore" | ||
], | ||
"folder_exclude_patterns": | ||
[ | ||
"build", | ||
"*.egg-info", | ||
"dist" | ||
] | ||
} | ||
], | ||
"settings": | ||
{ | ||
"font_size": 10, | ||
"tab_size": 4, | ||
"indent_spaces": true, | ||
"rulers": [120], | ||
"translate_tabs_to_spaces": true, | ||
"trim_automatic_white_space": true, | ||
"bold_folder_labels": true, | ||
"ensure_newline_at_eof_on_save": true, | ||
"default_line_ending": "unix" | ||
} | ||
} |
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,28 +1,27 @@ | ||
#!/usr/bin/python | ||
|
||
import os | ||
|
||
from . import FILETYPES | ||
|
||
|
||
def _list_files(files, dirs): | ||
file_list = [] | ||
|
||
# get all the files from the CWD | ||
if not files and not dirs: | ||
for r, _, fs in os.walk(os.getcwd()): | ||
files.extend([os.path.join(r, f) for f in fs]) | ||
|
||
# get all of the files from the given dirs | ||
for d in dirs: | ||
if os.path.isdir(d): | ||
for r, ds, fs in os.walk(d): | ||
files.extend([os.path.join(r, f) for f in fs]) | ||
|
||
# make sure that the given files are YAML files and exist. | ||
for f in files: | ||
if os.path.isfile(f): | ||
if os.path.splitext(f)[1].strip('.') in FILETYPES: | ||
file_list.append(os.path.relpath(f)) | ||
|
||
return list(set(file_list)) | ||
#!/usr/bin/python | ||
|
||
import os | ||
|
||
from . import FILETYPES | ||
|
||
|
||
def _list_files(files, dirs): | ||
def _walk(d): | ||
output = [] | ||
if os.path.isdir(d): | ||
for r, _, fs in os.walk(d): | ||
output.extend([os.path.join(r, f) for f in fs]) | ||
return output | ||
|
||
output = [] | ||
# get all the files from the CWD | ||
if not files and not dirs: | ||
output.extend(_walk(os.getcwd())) | ||
else: | ||
# get all of the files from the given dirs | ||
for d in dirs: | ||
output.extend(_walk(d)) | ||
# make sure that the given files are YAML files and exist. | ||
output.extend([f for f in files if os.path.isfile(f)]) | ||
|
||
return list(set([os.path.relpath(f) for f in output if os.path.splitext(f)[1].strip('.') in FILETYPES])) |
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,48 +1,61 @@ | ||
#!/usr/bin/python | ||
|
||
import os | ||
import shutil | ||
import unittest | ||
|
||
from . import TESTFILES, TESTDATA, TESTROOT, TESTFILES_ANIMALS, TESTFILES_PEOPLE | ||
from . import setup_file_system, write_file | ||
from batchy.utils import _list_files | ||
|
||
|
||
class TestListFiles(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
# setup the test files | ||
cls.cwd = os.getcwd() | ||
os.chdir(os.path.dirname(__file__)) | ||
setup_file_system(TESTFILES) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
# remove the test files | ||
shutil.rmtree(TESTROOT) | ||
os.chdir(cls.cwd) | ||
|
||
def setUp(self): | ||
# make sure that each test starts with the same data | ||
for f, data in TESTDATA.items(): | ||
write_file(f, data) | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test__list_files_empty_lists(self): | ||
files = _list_files([], []) | ||
files.sort() | ||
self.assertEqual(files, TESTFILES) | ||
|
||
def test__list_files_given_dirs(self): | ||
files = _list_files([], ['files/people']) | ||
files.sort() | ||
self.assertEqual(files, TESTFILES_PEOPLE) | ||
|
||
def test__list_files_given_files(self): | ||
focus = ['files/people/bob.yml', 'files/people/jeff.yml'] | ||
files = _list_files(focus, []) | ||
files.sort() | ||
self.assertEqual(files, focus) | ||
#!/usr/bin/python | ||
|
||
import os | ||
import shutil | ||
import unittest | ||
|
||
from . import TESTDATA, TESTROOT | ||
from . import TESTFILES, TESTFILES_ANIMALS, TESTFILES_PEOPLE | ||
from . import setup_file_system, write_file | ||
from batchy.utils import _list_files | ||
|
||
|
||
class TestListFiles(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
# setup the test files | ||
cls.cwd = os.getcwd() | ||
os.chdir(os.path.dirname(__file__)) | ||
setup_file_system(TESTFILES) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
# remove the test files | ||
shutil.rmtree(TESTROOT) | ||
os.chdir(cls.cwd) | ||
|
||
def setUp(self): | ||
# make sure that each test starts with the same data | ||
for f, data in TESTDATA.items(): | ||
write_file(f, data) | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test__utils__list_files__empty_lists(self): | ||
files = _list_files([], []) | ||
files.sort() | ||
self.assertEqual(files, TESTFILES) | ||
|
||
def test__utils__list_files__given_dirs(self): | ||
files = _list_files([], ['files/people']) | ||
files.sort() | ||
self.assertEqual(files, TESTFILES_PEOPLE) | ||
|
||
def test__utils__list_files__given_files(self): | ||
focus = ['files/people/bob.yml', 'files/people/jeff.yml'] | ||
files = _list_files(focus, []) | ||
files.sort() | ||
self.assertEqual(files, focus) | ||
|
||
def test__utils__list_files__given_files_and_dirs(self): | ||
focus = ['files/people/bob.yml', 'files/people/jeff.yml'] | ||
output = _list_files(focus, ['files/animals']) | ||
output.sort() | ||
files = focus + TESTFILES_ANIMALS | ||
files.sort() | ||
print TESTFILES_ANIMALS | ||
print files | ||
print output | ||
self.assertEqual(files, output) | ||
|