Skip to content

Commit

Permalink
Merge branch 'hotfix/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
akuzminsky committed Feb 10, 2017
2 parents 3d6f983 + 4c6ac74 commit 6014b9a
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 35 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ include CONTRIBUTING.rst
include HISTORY.rst
include LICENSE
include README.rst
include requirements.txt
include requirements_dev.txt

recursive-include tests *
recursive-exclude * __pycache__
Expand Down
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,34 @@ clean-test: clean-pyc ## remove test and coverage artifacts
rm -fr htmlcov/

lint: ## check style with flake8
flake8 twindb_table_compare tests
tox -e flake8

vagrant-up:
cd vagrant && vagrant up

vagrant-provision:
cd vagrant && vagrant provision

test: lint vagrant-up vagrant-provision ## run tests quickly with the default Python
py.test
.PHONY: bootstrap
bootstrap: ## bootstrap the development environment
pip install -U "setuptools==32.3.1"
pip install -U "pip==9.0.1"
pip install -U "pip-tools>=1.6.0"
pip-sync requirements.txt requirements_dev.txt
pip install --editable .

.PHONY: rebuild-requirements
rebuild-requirements: ## Rebuild requirements files requirements.txt and requirements_dev.txt
pip-compile --verbose --no-index --output-file requirements.txt requirements.in
pip-compile --verbose --no-index --output-file requirements_dev.txt requirements_dev.in

.PHONY: upgrade-requirements
upgrade-requirements: ## Upgrade requirements
pip-compile --upgrade --verbose --no-index --output-file requirements.txt requirements.in
pip-compile --upgrade --verbose --no-index --output-file requirements_dev.txt requirements_dev.in

test: ## run tests quickly with the default Python
py.test -vx tests/unit/


test-all: ## run tests on every Python version with tox
Expand Down
2 changes: 2 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Click>=6.0
mysql
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --no-index --output-file requirements.txt requirements.in
#
Click==6.7
MySQL-python==1.2.5 # via mysql
mysql==0.0.1
9 changes: 9 additions & 0 deletions requirements_dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bumpversion
flake8
tox
pytest
mock
coverage
codecov
pytest-cov
Sphinx
45 changes: 34 additions & 11 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
click==6.6
pip==8.1.2
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --no-index --output-file requirements_dev.txt requirements_dev.in
#
alabaster==0.7.9 # via sphinx
argparse==1.4.0 # via codecov
babel==2.3.4 # via sphinx
bumpversion==0.5.3
wheel==0.29.0
watchdog==0.8.3
flake8==3.0.4
tox==2.3.1
codecov==2.0.5
configparser==3.5.0 # via flake8
coverage==4.2
Sphinx==1.4.5
PyYAML==3.12
docutils==0.13.1 # via sphinx
enum34==1.1.6 # via flake8
flake8==3.0.4
funcsigs==1.0.2 # via mock
imagesize==0.7.1 # via sphinx
Jinja2==2.9.5 # via sphinx
MarkupSafe==0.23 # via jinja2
mccabe==0.5.3 # via flake8
mock==2.0.0
pbr==1.10.0 # via mock
pluggy==0.3.1 # via tox
py==1.4.32 # via pytest, tox
pycodestyle==2.0.0 # via flake8
pyflakes==1.2.3 # via flake8
Pygments==2.2.0 # via sphinx
pytest-cov==2.4.0
pytest==3.0.2
mysql
codecov
pytest-cov
pytz==2016.10 # via babel
requests==2.13.0 # via codecov
six==1.10.0 # via mock, sphinx
snowballstemmer==1.2.1 # via sphinx
sphinx==1.4.5
tox==2.3.1
virtualenv==15.1.0 # via tox
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.1
current_version = 1.0.2
commit = True
tag = False

Expand Down
17 changes: 7 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pip.req import parse_requirements
from setuptools import setup

with open('README.rst') as readme_file:
Expand All @@ -9,19 +9,16 @@
with open('HISTORY.rst') as history_file:
history = history_file.read()

requirements = [
'Click>=6.6',
'mysql'
]

test_requirements = [
'Click>=6.6',
'mysql'
]
requirements = [str(ir.req) for ir in
parse_requirements('requirements.txt', session=False)]

test_requirements = [str(ir.req) for ir in
parse_requirements('requirements_dev.txt', session=False)]

setup(
name='twindb_table_compare',
version='1.0.1',
version='1.0.2',
description="TwinDB Table Compare reads percona.checksums from the master "
"and slave and shows what records are difference "
"if there are any inconsistencies.",
Expand Down
2 changes: 1 addition & 1 deletion twindb_table_compare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = 'Aleksandr Kuzminsky'
__email__ = 'aleks@twindb.com'
__version__ = '1.0.1'
__version__ = '1.0.2'
6 changes: 4 additions & 2 deletions twindb_table_compare/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
@click.option('--tbl', default='checksums',
help='Table with checksums')
@click.option('--vertical', default=False, is_flag=True,
help='Print result vertically. Otherwise will print one record in one line')
help='Print result vertically. '
'Otherwise will print one record in one line')
@click.argument('slave', default='localhost', required=False)
def main(user, password, db, tbl, slave, vertical):
"""twindb_table_compare reads percona.checksums from the master and slave
Expand All @@ -29,7 +30,8 @@ def main(user, password, db, tbl, slave, vertical):
ch_tbl=tbl):
twindb_table_compare.get_inconsistencies(d, t, slave, user,
password,
ch_db=db, ch_tbl=tbl, vertical=vertical)
ch_db=db, ch_tbl=tbl,
vertical=vertical)


if __name__ == "__main__":
Expand Down
22 changes: 15 additions & 7 deletions twindb_table_compare/twindb_table_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,17 @@ def diff(master_lines, slave_lines):
result = ""
for line in unified_diff(sorted(master_lines), sorted(slave_lines)):
if not line.startswith('---') and not line.startswith('+++'):
if not line.endswith('\n'):
# print(result)
line += '\n'
pass
if line.startswith('+'):
result += _green(line)
elif line.startswith('-'):
result += _red(line)
else:
result += line
if not result.endswith('\n'):
result += '\n'

return result


Expand All @@ -172,7 +175,8 @@ def get_fileds(conn, db, tbl):
return ', '.join(fields)


def build_chunk_query(db, tbl, chunk, conn, ch_db='percona', ch_tbl='checksusm'):
def build_chunk_query(db, tbl, chunk, conn, ch_db='percona',
ch_tbl='checksusm'):

log.info("# %s.%s, chunk %d" % (db, tbl, chunk))
chunk_index = get_chunk_index(conn, db, tbl, chunk,
Expand Down Expand Up @@ -303,7 +307,8 @@ def print_horizontal(cur_master, cur_slave, query):
def print_vertical(master, slave, user, passwd, query):
log.info("Executing: %s" % query)

proc = Popen(['mysql', '-h', master, '-u', user, '-p%s' % passwd, '-e', '%s\G' % query],
proc = Popen(['mysql', '-h', master, '-u', user, '-p%s' % passwd,
'-e', '%s\G' % query],
stdout=PIPE, stderr=PIPE)
master_cout, master_cerr = proc.communicate()
if proc.returncode:
Expand All @@ -312,7 +317,8 @@ def print_vertical(master, slave, user, passwd, query):
exit(1)

log.info("Executing: %s" % query)
proc = Popen(['mysql', '-h', slave, '-u', user, '-p%s' % passwd, '-e', '%s\G' % query],
proc = Popen(['mysql', '-h', slave, '-u', user, '-p%s' % passwd,
'-e', '%s\G' % query],
stdout=PIPE, stderr=PIPE)
slave_cout, slave_cerr = proc.communicate()
if proc.returncode:
Expand Down Expand Up @@ -350,13 +356,15 @@ def get_inconsistencies(db, tbl, slave, user, passwd,
# generate WHERE clause to fetch records of the chunk
for chunk, in chunks:

query = build_chunk_query(db, tbl, chunk, conn_slave, ch_db=ch_db, ch_tbl=ch_tbl)
query = build_chunk_query(db, tbl, chunk, conn_slave, ch_db=ch_db,
ch_tbl=ch_tbl)

if vertical:
diffs = print_vertical(master, slave, user, passwd, query)
else:
diffs = print_horizontal(cur_master, cur_slave, query)
log.info("Differences between slave %s and its master:" % slave)
log.info("Differences between slave %s and its master:"
% slave)

print(diffs)

Expand Down

0 comments on commit 6014b9a

Please sign in to comment.