Beispiel #1
0
 def move_file(src, dest, attr=None):
     self.debug("Moving file '%s' to '%s'", src, dest)
     dest_dir = os.path.dirname(dest)
     safe_mkdirs(dest_dir, "input file destination", attr)
     d = deferToThread(shutil.move, src, dest)
     d.addErrback(move_failed, src, dest)
     return d
 def do_setup_watchers(self):
     for name, virt_dir in self._named_profiles.items():
         local_dir = virt_dir.localize(self._local)
         safe_mkdirs(local_dir, "monitored", self._pathAttr)
         watcher = DirectoryWatcher(self, local_dir, timeout=self._scanPeriod)
         watcher.connect('file-added', self._file_added, virt_dir, name)
         watcher.connect('file-completed', self._file_completed, virt_dir, name)
         watcher.connect('file-removed', self._file_removed, virt_dir, name)
         watcher.start()
         self.watchers.append(watcher)
    def do_setup(self):
        try:
            properties = self.config['properties']
            # setup the passive profiles
            if self.http_profiles:
                root = Resource()
                for p in self.http_profiles:
                    vdir = self.profiles_virtualbase[p]
                    root.putChild(p, RequestHandler(self, vdir, callback=self._file_added_http, profile_name=p))
                    local_dir = vdir.localize(self._local)
                    safe_mkdirs(local_dir, "monitored")
                factory = Site(root)
                self.port = properties.get("port", 7680)
                self._listener = IReactorTCP(reactor).listenTCP(self.port, factory)
                if not self.port:
                    # setting port to 0 means random port, read and store.
                    self.port = self._listener.getHost().port
            # setup the active profiles
            self._scanPeriod = properties.get("scan-period", 10)
            for p in self.active_profiles:
                vdir = self.profiles_virtualbase[p]
                local_dir = vdir.localize(self._local)
                safe_mkdirs(local_dir, "monitored", self._pathAttr)
                watcher = DirectoryWatcher(self, local_dir, p, timeout=self._scanPeriod)
                watcher.connect('file-added', self._file_added, vdir, p)
                watcher.connect('file-completed', self._file_completed, vdir, p)
                watcher.connect('file-removed', self._file_removed, vdir, p)
                watcher.start()
                self.watchers.append(watcher)
            setup_callback = properties.get('setup-callback')
            if setup_callback:
                data = {'hostname': gethostname(), 'port': self.port}
                url = setup_callback % data
                getPage(url, method='POST')
                
                

            # htpp://sdfsdkfjlsdjfklsdf/?host=%(host)s&myport=%(port)s
            # htpp://sdfsdkfjlsdjfklsdf/?myip=123.123.123.123&myport=1234
            # TODO: make the http call to register.
        except:
            return fail(self._unexpected_error(task="component setup"))