-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from thombashi/develop
Fix exit code
- Loading branch information
Showing
6 changed files
with
89 additions
and
17 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
click | ||
DataProperty>=0.7.2 | ||
DataProperty>=0.8.1 | ||
path.py | ||
SimpleSQLite>=0.4.2 | ||
SimpleSQLite>=0.4.6 |
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,3 @@ | ||
from __future__ import with_statement | ||
import os.path | ||
import setuptools | ||
import sys | ||
|
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 @@ | ||
VERSION = "0.1.4" | ||
VERSION = "0.1.5" |
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,29 @@ | ||
# encoding: utf-8 | ||
|
||
""" | ||
.. codeauthor:: Tsuyoshi Hombashi <[email protected]> | ||
""" | ||
|
||
from __future__ import absolute_import | ||
|
||
|
||
class ResultCounter(object): | ||
|
||
def __init__(self): | ||
self.__success_count = 0 | ||
self.__fail_count = 0 | ||
|
||
def inc_success(self): | ||
self.__success_count += 1 | ||
|
||
def inc_fail(self): | ||
self.__fail_count += 1 | ||
|
||
def get_return_code(self): | ||
if self.__success_count > 0: | ||
return 0 | ||
|
||
if self.__fail_count > 0: | ||
return 1 | ||
|
||
return 2 |
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,15 +1,14 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
""" | ||
.. codeauthor:: Tsuyoshi Hombashi <[email protected]> | ||
""" | ||
|
||
|
||
from __future__ import absolute_import | ||
import collections | ||
import re | ||
import sys | ||
|
||
import click | ||
import dataproperty | ||
|
@@ -18,6 +17,8 @@ | |
from simplesqlite.loader import ValidationError | ||
from simplesqlite.loader import InvalidDataError | ||
|
||
from ._counter import ResultCounter | ||
|
||
|
||
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) | ||
|
||
|
@@ -81,8 +82,8 @@ def file(files, output_path): | |
""" | ||
|
||
con = create_database(output_path) | ||
result_counter = ResultCounter() | ||
|
||
convert_count = 0 | ||
for file_path in files: | ||
if not path.Path(file_path).isfile(): | ||
continue | ||
|
@@ -96,12 +97,17 @@ def file(files, output_path): | |
for tabledata in loader.load(): | ||
click.echo("convert '{:s}' to '{:s}' table".format( | ||
file_path, tabledata.table_name)) | ||
con.create_table_from_tabledata(tabledata) | ||
convert_count += 1 | ||
except (ValueError, ValidationError, InvalidDataError): | ||
continue | ||
|
||
return 0 if convert_count == 0 else 1 | ||
try: | ||
con.create_table_from_tabledata(tabledata) | ||
result_counter.inc_success() | ||
except (ValueError, IOError): | ||
result_counter.inc_fail() | ||
continue | ||
except (ValidationError, InvalidDataError): | ||
result_counter.inc_fail() | ||
|
||
sys.exit(result_counter.get_return_code()) | ||
|
||
|
||
@cmd.command() | ||
|
@@ -121,17 +127,26 @@ def gs(credentials, title, output_path): | |
""" | ||
|
||
con = create_database(output_path) | ||
result_counter = ResultCounter() | ||
|
||
loader = simplesqlite.loader.GoogleSheetsTableLoader() | ||
loader.source = credentials | ||
loader.title = title | ||
|
||
for tabledata in loader.load(): | ||
click.echo("convert '{:s}' to '{:s}' table".format( | ||
title, tabledata.table_name)) | ||
con.create_table_from_tabledata(tabledata) | ||
try: | ||
for tabledata in loader.load(): | ||
click.echo("convert '{:s}' to '{:s}' table".format( | ||
title, tabledata.table_name)) | ||
|
||
try: | ||
con.create_table_from_tabledata(tabledata) | ||
result_counter.inc_success() | ||
except (ValidationError, InvalidDataError): | ||
result_counter.inc_fail() | ||
except (ValidationError, InvalidDataError): | ||
result_counter.inc_fail() | ||
|
||
return 0 | ||
sys.exit(result_counter.get_return_code()) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
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,29 @@ | ||
# encoding: utf-8 | ||
|
||
""" | ||
.. codeauthor:: Tsuyoshi Hombashi <[email protected]> | ||
""" | ||
|
||
|
||
import pytest | ||
from sqlitebiter._counter import ResultCounter | ||
|
||
|
||
class Test_ResultCounter(object): | ||
|
||
@pytest.mark.parametrize(["success", "fail", "expected"], [ | ||
[0, 0, 2], | ||
[1, 0, 0], | ||
[1, 1, 0], | ||
[0, 1, 1], | ||
]) | ||
def test_normal(self, success, fail, expected): | ||
result_counter = ResultCounter() | ||
|
||
for _i in range(success): | ||
result_counter.inc_success() | ||
|
||
for _i in range(fail): | ||
result_counter.inc_fail() | ||
|
||
assert result_counter.get_return_code() == expected |