Changeset - cdbb6d29d98e
[Not reviewed]
0 10 0
Lance Edgar (lance) - 7 years ago 2018-02-15 12:47:20
lance@edbob.org
More tweaks for python 3
10 files changed with 33 insertions and 30 deletions:
0 comments (0 inline, 0 general)
rattail/commands/core.py
Show inline comments
 
@@ -680,13 +680,13 @@ class FileMonitorCommand(Subcommand):
 

	
 
        start = subparsers.add_parser('start', help="Start service")
 
        start.set_defaults(subcommand='start')
 
        stop = subparsers.add_parser('stop', help="Stop service")
 
        stop.set_defaults(subcommand='stop')
 

	
 
        if sys.platform == 'linux2':
 
        if sys.platform in ('linux', 'linux2'):
 
            parser.add_argument('-p', '--pidfile',
 
                                help="Path to PID file.", metavar='PATH')
 
            parser.add_argument('--daemonize', action='store_true', default=True, # TODO: should default to False
 
                                help="Daemonize when starting.")
 
            parser.add_argument('--no-daemonize',
 
                                '-D', '--do-not-daemonize', # TODO: (re)move these?
 
@@ -706,13 +706,13 @@ class FileMonitorCommand(Subcommand):
 
            remove.set_defaults(subcommand='remove')
 

	
 
            uninstall = subparsers.add_parser('uninstall', help="Uninstall (remove) service")
 
            uninstall.set_defaults(subcommand='remove')
 

	
 
    def run(self, args):
 
        if sys.platform == 'linux2':
 
        if sys.platform in ('linux', 'linux2'):
 
            from rattail.filemon import linux as filemon
 

	
 
            if args.subcommand == 'start':
 
                filemon.start_daemon(self.config, args.pidfile, args.daemonize)
 

	
 
            elif args.subcommand == 'stop':
rattail/filemon/actions.py
Show inline comments
 
@@ -26,13 +26,13 @@ File Monitor Actions
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
import os
 
import sys
 
import time
 
import Queue
 
from six.moves import queue
 
import socket
 
import logging
 
from traceback import format_exception
 

	
 
from rattail.mail import send_email
 

	
 
@@ -86,13 +86,13 @@ def perform_actions(profile):
 

	
 
        # Suspend execution briefly, to avoid consuming so much CPU...
 
        time.sleep(0.01)
 

	
 
        try:
 
            path = profile.queue.get_nowait()
 
        except Queue.Empty:
 
        except queue.Empty:
 
            pass
 
        except StopProcessing:
 
            stop = True
 
        else:
 
            log.debug(u"queue contained a file: {0}".format(repr(path)))
 

	
rattail/filemon/config.py
Show inline comments
 
@@ -196,13 +196,13 @@ class Profile(object):
 
            action.spec = class_
 
            action.action = load_object(action.spec)(self.config)
 

	
 
        action.args = self._config_list(u'action.{0}.args'.format(name))
 

	
 
        action.kwargs = {}
 
        pattern = re.compile(ur'^{0}\.action\.{1}\.kwarg\.(?P<keyword>\w+)$'.format(self.key, name), re.IGNORECASE)
 
        pattern = re.compile(r'^{0}\.action\.{1}\.kwarg\.(?P<keyword>\w+)$'.format(self.key, name), re.IGNORECASE)
 
        for option in self.config.options(u'rattail.filemon'):
 
            match = pattern.match(option)
 
            if match:
 
                action.kwargs[match.group(u'keyword')] = self.config.get(u'rattail.filemon', option)
 

	
 
        action.retry_attempts = self._config_int(u'action.{0}.retry_attempts'.format(name), minimum=1)
rattail/filemon/linux.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2018 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
@@ -21,15 +21,15 @@
 
#
 
################################################################################
 
"""
 
File Monitor for Linux
 
"""
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 
import Queue
 
from six.moves import queue
 
import logging
 

	
 
import pyinotify
 

	
 
from rattail.daemon import Daemon
 
from rattail.threads import Thread
 
@@ -97,13 +97,13 @@ class FileMonitorDaemon(Daemon):
 
                | pyinotify.IN_MOVED_TO)
 

	
 
        monitored = load_profiles(self.config)
 
        for key, profile in monitored.items():
 

	
 
            # Create a file queue for the profile.
 
            profile.queue = Queue.Queue()
 
            profile.queue = queue.Queue()
 

	
 
            # Perform setup for each of the watched folders.
 
            for path in profile.dirs:
 

	
 
                # Maybe put all pre-existing files in the queue.
 
                if profile.process_existing:
rattail/filemon/win32.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2018 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
@@ -21,18 +21,18 @@
 
#
 
################################################################################
 
"""
 
File Monitor for Windows
 
"""
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 
import os
 
import time
 
import datetime
 
import Queue
 
from six.moves import queue
 
import logging
 

	
 
from rattail.win32.service import Service
 
from rattail.threads import Thread
 
from rattail.filemon.config import load_profiles
 
from rattail.filemon.actions import perform_actions
 
@@ -68,13 +68,13 @@ class RattailFileMonitor(Service):
 
            return False
 

	
 
        # Create monitor and action threads for each profile.
 
        for key, profile in self.monitored.items():
 

	
 
            # Create a file queue for the profile.
 
            profile.queue = Queue.Queue()
 
            profile.queue = queue.Queue()
 

	
 
            # Perform setup for each of the watched folders.
 
            for i, path in enumerate(profile.dirs, 1):
 

	
 
                # Maybe put all pre-existing files in the queue.
 
                if profile.process_existing:
rattail/sil/writer.py
Show inline comments
 
@@ -48,13 +48,13 @@ class Writer(Object):
 
        if path is None:
 
            path = self.temp_path(suffix='.sil')
 
        self.sil_path = path
 
        self.fileobj = self.get_fileobj()
 

	
 
    def get_fileobj(self):
 
        return open(self.sil_path, 'w')
 
        return open(self.sil_path, 'wb')
 

	
 
    def close(self):
 
        self.fileobj.close()
 

	
 
    @classmethod
 
    def temp_path(cls, **kwargs):
rattail/tests/filemon/test_actions.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 
import os
 
import time
 
import Queue
 
from six.moves import queue
 
from unittest import TestCase
 

	
 
from mock import Mock, patch, call
 
from fixture import TempIO
 

	
 
from rattail.config import make_config, RattailConfig
 
@@ -37,13 +37,13 @@ class TestPerformActions(TestCase):
 

	
 
    def get_profile(self, stop_on_error=False):
 
        profile = Profile(self.config, u'foo')
 
        profile.stop_on_error = stop_on_error
 
        profile.queue = Mock()
 
        profile.queue.get_nowait.side_effect = [
 
            Queue.Empty, # for coverage sake; will be effectively skipped
 
            queue.Empty, # for coverage sake; will be effectively skipped
 
            self.tmp.putfile(u'file1', u''),
 
            self.tmp.putfile(u'file2', u''),
 
            self.tmp.putfile(u'file3', u''),
 
            actions.StopProcessing,
 
            ]
 
        return profile
rattail/tests/filemon/test_linux.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 
import Queue
 
from six.moves import queue
 
from unittest import TestCase
 

	
 
from mock import Mock
 
from fixture import TempIO
 

	
 
from rattail.config import make_config
 
@@ -20,13 +20,13 @@ class TestEventHandler(TestCase):
 
        self.config = make_config([])
 
        self.config.set(u'rattail.filemon', u'monitor', u'foo')
 
        self.config.set(u'rattail.filemon', u'foo.dirs', self.tmp)
 
        self.config.set(u'rattail.filemon', u'foo.actions', u'noop')
 
        self.config.set(u'rattail.filemon', u'foo.action.noop.func', u'rattail.filemon.actions:noop')
 
        self.profile = Profile(self.config, u'foo')
 
        self.profile.queue = Queue.Queue()
 
        self.profile.queue = queue.Queue()
 
        self.handler = linux.EventHandler()
 
        self.handler.my_init(self.profile)
 

	
 
    def test_in_access_event_does_nothing(self):
 
        event = Mock(pathname=self.tmp.putfile(u'file', u''))
 
        self.handler.process_IN_ACCESS(event)
rattail/tests/filemon/test_util.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 
import Queue
 
from six.moves import queue
 
from unittest import TestCase
 

	
 
from fixture import TempIO
 

	
 
from rattail.config import make_config
 
from rattail.filemon import util
 
@@ -19,13 +19,13 @@ class TestQueueExisting(TestCase):
 
        self.config = make_config([])
 
        self.config.set(u'rattail.filemon', u'monitor', u'foo')
 
        self.config.set(u'rattail.filemon', u'foo.dirs', self.tmp)
 
        self.config.set(u'rattail.filemon', u'foo.actions', u'noop')
 
        self.config.set(u'rattail.filemon', u'foo.action.noop.func', u'rattail.filemon.actions:noop')
 
        self.profile = Profile(self.config, u'foo')
 
        self.profile.queue = Queue.Queue()
 
        self.profile.queue = queue.Queue()
 

	
 
    def test_nothing_queued_if_no_files_exist(self):
 
        util.queue_existing(self.profile, self.tmp)
 
        self.assertTrue(self.profile.queue.empty())
 

	
 
    def test_normal_files_are_queued_but_not_folders(self):
rattail/vendors/catalogs.py
Show inline comments
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2018 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
@@ -72,14 +72,17 @@ class CatalogParser(object):
 
        Convert a value to a decimal, unless it's ``None``.
 
        """
 
        if value is None:
 
            return None
 

	
 
        # No reason to convert integers, really.
 
        if isinstance(value, (Decimal, int, long)):
 
        if isinstance(value, six.integer_types):
 
            return value
 
        if isinstance(value, Decimal):
 
            return value
 

	
 
        if isinstance(value, float):
 
            value = "{{0:0.{0}f}}".format(scale).format(value)
 
        else:
 
            value = value.strip()
 
        return Decimal(value)
 

	
0 comments (0 inline, 0 general)