Skip to content

Commit

Permalink
Merge pull request akissa#4 from treibholz/python3_compatibility
Browse files Browse the repository at this point in the history
Python3 compatibility
  • Loading branch information
akissa authored Aug 27, 2019
2 parents 6ef1cfa + 0623740 commit 9b81846
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
25 changes: 16 additions & 9 deletions clamavmirror/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
-u andrew -g staff -a db.za.clamav.net \
-l ~/Downloads/
"""
from __future__ import print_function
import os
import pwd
import grp
Expand All @@ -69,7 +70,13 @@
import hashlib

from shutil import move
from Queue import Queue

# Queue is called queue in python3
if sys.version_info.major < 3:
from Queue import Queue
else:
from queue import Queue

from threading import Thread
from optparse import OptionParser
from subprocess import PIPE, Popen
Expand All @@ -83,7 +90,7 @@

VERSION_INFO = (0, 0, 4)
__author__ = "Andrew Colin Kissa"
__copyright__ = u"© 2016-2019 Andrew Colin Kissa"
__copyright__ = "© 2016-2019 Andrew Colin Kissa"
__email__ = "andrew@topdog.za.net"
__version__ = ".".join(map(str, VERSION_INFO))

Expand Down Expand Up @@ -112,24 +119,24 @@ def get_md5(string):
hasher = hashlib.md5()
except BaseException:
hasher = hashlib.new('md5', usedForSecurity=False)
hasher.update(string)
hasher.update(string.encode('utf-8'))
return hasher.hexdigest()


def error(msg):
"""print to stderr"""
print >> sys.stderr, msg
print(msg, file=sys.stderr)


def info(msg):
"""print to stdout"""
print >> sys.stdout, msg
print(msg, file=sys.stdout)


def deploy_signature(source, dest, user=None, group=None):
"""Deploy a signature fole"""
move(source, dest)
os.chmod(dest, 0644)
os.chmod(dest, 0o644)
if user and group:
try:
uid = pwd.getpwnam(user).pw_uid
Expand All @@ -149,7 +156,7 @@ def get_txt_record(hostname):
"""Get the text record"""
try:
answers = query(hostname, 'TXT')
return answers[0].strings[0]
return answers[0].strings[0].decode()
except (IndexError, NXDOMAIN):
return ''

Expand All @@ -162,7 +169,7 @@ def get_local_version(sigdir, sig):
cmd = ['sigtool', '-i', filename]
sigtool = Popen(cmd, stdout=PIPE, stderr=PIPE)
while True:
line = sigtool.stdout.readline()
line = sigtool.stdout.readline().decode()
if line and line.startswith('Version:'):
version = line.split()[1]
break
Expand Down Expand Up @@ -218,7 +225,7 @@ def download_sig(opts, sig, version=None):
data = req.data
code = req.status
if req.status == 200:
with open(filename, 'w') as handle:
with open(filename, 'wb') as handle:
handle.write(data)
downloaded = os.path.exists(filename)
return downloaded, code
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
author_email="andrew@topdog.za.net",
url="https://github.com/akissa/clamavmirror",
license="MPL 2.0",
packages=[],
packages=['clamavmirror'],
entry_points={
'console_scripts': [
'clamavmirror=clamavmirror:main'
Expand All @@ -63,6 +63,7 @@ def main():
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.7',
'Topic :: Software Development :: Libraries :: Python Modules',
'Intended Audience :: System Administrators',
'Environment :: Console',
Expand Down

0 comments on commit 9b81846

Please sign in to comment.