Skip to content

Commit

Permalink
Reviewed requirements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Delle Cave committed Nov 22, 2019
1 parent 9b08cbc commit 28f2007
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 10 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
python-sonicprobe (0.3.6) unstable; urgency=medium

* Reviewed requirements.

-- Adrien DELLE CAVE (Decryptus) <adc@doowan.net> Fri, 22 Nov 2019 09:58:04 +0100

python-sonicprobe (0.3.5) unstable; urgency=medium

* Added class MySQLConfigVersion.

-- Adrien DELLE CAVE (Decryptus) <adc@doowan.net> Fri, 22 Nov 2019 09:53:39 +0100

python-sonicprobe (0.3.4) unstable; urgency=medium

* Added methods network.valid_sub_domain_tld and network.parse_domain_cert.
Expand Down
2 changes: 1 addition & 1 deletion RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.4
0.3.6
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.4
0.3.6
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Homepage: https://github.com/decryptus/sonicprobe
Package: python-sonicprobe
Architecture: all
Homepage: https://github.com/decryptus/sonicprobe
Depends: ${misc:Depends}, lsb-release, python-dev (>= 2.7~), python-httpdis (>= 0.6.2), python-pip, python-openssl, python-psutil, python-pycurl, python-unidecode, python-yaml
Depends: ${misc:Depends}, lsb-release, python-dev (>= 2.7~), python-httpdis (>= 0.6.4), python-pip, python-openssl, python-psutil, python-pycurl, python-unidecode, python-yaml
Suggests: python-mysqldb, python-psycopg2, python-sqlite
Description: SonicProbe python libraries
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
httpdis>=0.6.2
httpdis>=0.6.4
pyOpenSSL
python-magic
psutil>=2.1
pycurl
PyYAML>=3.10
#pyserial
Unidecode
semantic_version
six>=1.12.0
#xmodem
4 changes: 2 additions & 2 deletions setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: sonicprobe
author: Adrien Delle Cave
author_email: pypi@doowan.net
copyright: '2019 Adrien Delle Cave'
release: '0.3.4'
version: '0.3.4'
release: '0.3.6'
version: '0.3.6'
license: License GPL-3
url: https://github.com/decryptus/sonicprobe
python_requires:
Expand Down
84 changes: 80 additions & 4 deletions sonicprobe/libs/mysql_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,89 @@

import os
import re
import subprocess

# pylint: disable=unused-import
from six.moves.configparser import ConfigParser, Error, NoSectionError, DuplicateSectionError, \
NoOptionError, InterpolationError, InterpolationMissingOptionError, \
InterpolationSyntaxError, InterpolationDepthError, ParsingError, \
MissingSectionHeaderError, _default_dict

try:
from six.moves import cStringIO as StringIO
except ImportError:
from six import StringIO

import six
import semantic_version

MYSQL_DEFAULT_HOST = 'localhost'
MYSQL_DEFAULT_PORT = 3306

MYSQLCLIENT_PARSE_VERS = re.compile(r'^mysql\s+Ver\s+(?P<version>[^\s]+)\s+Distrib\s+(?P<distrib>[^\s,]+)').match
MYSQLDUMP_PARSE_VERS = re.compile(r'^mysqldump\s+Ver\s+(?P<version>[^\s]+)\s+Distrib\s+(?P<distrib>[^\s,]+)').match


class MySQLConfigVersion(object):
def __init__(self, default_file = 'client.cnf', custom_file = "", config_dir = None):
self._config_dir = config_dir
self._default_file = default_file or ""
self._custom_file = custom_file or ""
self._myconf = MySQLConfigParser()

def _read_file(self, filepath):
if self._config_dir and not filepath.startswith(os.path.sep):
filepath = os.path.join(self._config_dir, filepath)

if not os.path.isfile(filepath):
return ""

with open(filepath, 'r') as f:
return f.read()

@staticmethod
def _set_specific_conf(cfg, section, version):
secname = "%s=%s" % (section, version)
if cfg.has_section(secname):
for x in cfg.items(secname):
cfg.set(*[section] + list(x))

def _check_conf_versions(self, cfg, section, version, vername = ""):
ver = semantic_version.Version(version, partial = True)
for x in ('major', 'minor', 'patch', 'prerelease', 'build'):
v = getattr(ver, x, None)
if not v:
break
if isinstance(v, tuple):
v = '.'.join(v)
vername += "%s." % v
self._set_specific_conf(cfg, section, vername.rstrip('.'))

def _get_config(self, section, progpath, parse_vers):
my_vers = parse_vers(subprocess.check_output((progpath, '--version')).strip())
myconf = StringIO("%s\n%s" % (self._read_file(self._default_file),
self._read_file(self._custom_file)))
self._myconf.readfp(myconf)
myconf.close()

if my_vers:
self._check_conf_versions(self._myconf,
section,
my_vers.group('version'),
'ver-')
self._check_conf_versions(self._myconf,
section,
my_vers.group('distrib'),
'dist-')

return self._myconf

def get_client(self):
return self._get_config('client', 'mysql', MYSQLCLIENT_PARSE_VERS)

def get_mysqldump(self):
return self._get_config('mysqldump', 'mysqldump', MYSQLDUMP_PARSE_VERS)


class MySQLConfigParser(ConfigParser):
if os.name == 'nt':
Expand All @@ -35,9 +111,9 @@ def getboolean(self, section, option, retint=False): # pylint: disable=arguments
if not retint:
return ret

return(int(ret))
return int(ret)

def read(self, filenames, encoding=None):
def read(self, filenames, encoding=None): # pylint: disable=arguments-differ
if isinstance(filenames, six.string_types):
filenames = [filenames]

Expand All @@ -49,7 +125,7 @@ def read(self, filenames, encoding=None):
if six.PY2:
return ConfigParser.read(self, file_ok)

return ConfigParser.read(self, file_ok, encoding)
return ConfigParser.read(self, file_ok, encoding) # pylint: disable=too-many-function-args

def readfp(self, fp, filename=None):
return ConfigParser.readfp(self, MySQLConfigParserFilter(fp), filename)
Expand All @@ -58,7 +134,7 @@ def read_file(self, f, source=None):
if six.PY2:
return ConfigParser.readfp(self, MySQLConfigParserFilter(f), source)

return ConfigParser.read_file(self, MySQLConfigParserFilter(f), source)
return ConfigParser.read_file(self, MySQLConfigParserFilter(f), source) # pylint: disable=no-member


class MySQLConfigParserFilter(object): # pylint: disable=useless-object-inheritance
Expand Down

0 comments on commit 28f2007

Please sign in to comment.