Example #1
0
 def configure(self, **kwargs):
     mask = 0
     values = []
     if 'x' in kwargs:
         mask |= ConfigWindow.X
         values.append(kwargs['x'])
     if 'y' in kwargs:
         mask |= ConfigWindow.Y
         values.append(kwargs['y'])
     if 'width' in kwargs:
         mask |= ConfigWindow.Width
         values.append(kwargs['width'])
     if 'height' in kwargs:
         mask |= ConfigWindow.Height
         values.append(kwargs['height'])
     if 'sibling' in kwargs:
         mask |= ConfigWindow.Sibling
         values.append(kwargs['sibling'])
     if 'stack_mode' in kwargs:
         mask |= ConfigWindow.StackMode
         values.append(kwargs['stack_mode'])
     try:
         self._conn.core.ConfigureWindow(self._wid, mask, values,
                                         True).check()
     except WindowError:
         log.exception('Error in `configure` method')
Example #2
0
 def get_name(self):
     try:
         return self.get_property('WM_NAME', 'STRING').to_string()
     except WindowError:
         # This may happen if we try to query a window that has been destroyed
         log.exception('Error in `configure` method')
         return ''
Example #3
0
  def processIpRequest(self,line):
    allocator = self.allocator
    try:
      parts = line.split(" ",2)
      if len(parts) != 2:
        error("got invalid line [%s]"%(line))
        self.transport.loseConnection()
        return
      
      domain, email_address = parts
      details = self.allocator.getIpAddress(domain,email_address)
      if details:
        info("Got %s for %s on %s"%(details, email_address, domain)) 
        self.transport.write("%s %s\n"%(details.getIpAddress(),details.getHeloHost()))
        self.email_address = email_address
        self.domain = domain
        self.ip_address = details
        self.state = STATE_IP_SENT
      else:
        warning("No available ip address for %s on %s"%(email_address,domain))
        self.transport.loseConnection()
        self.state = STATE_COMPLETED

    except Exception as e:
      exception(e)
      self.transport.looseConnection()
Example #4
0
    def _connect(self):
        try:
            if (self.dev == ""):
                SerialGamePad.find_serial_devices(self._hardwareID)

                if len(SerialGamePad.devices) > 0:
                    self.dev = SerialGamePad.devices[0]
                    log.info("Using COM Port: %s", self.dev)

            try:
                self._com = serial.Serial(self.dev, timeout=5)
            except serial.SerialException as e:
                ports = SerialGamePad.find_serial_devices(self._hardwareID)
                error = "Invalid port specified. No COM ports available."
                if len(ports) > 0:
                    error = "Invalid port specified. Try using one of: \n" + \
                        "\n".join(ports)
                log.info(error)
                raise SerialPadError(error)

            packet = generate_header(CMDTYPE.INIT, 0)
            self._com.write(packet)

            resp = self._com.read(1)
            if len(resp) == 0:
                SerialGamePad._comError()

            return ord(resp)

        except serial.SerialException as e:
            error = "Unable to connect to the device. Please check that it is connected and the correct port is selected."
            log.exception(e)
            log.error(error)
            raise e
Example #5
0
def run(args):
	from manifest import Manifest
	manifest = Manifest(args.manifest)

	from tasklist import TaskList
	tasklist = TaskList()
	tasklist.load('resolve_tasks', manifest)

	from bootstrapinfo import BootstrapInformation
	bootstrap_info = BootstrapInformation(manifest=manifest, debug=args.debug)

	try:
		tasklist.run(info=bootstrap_info, dry_run=args.dry_run)
		log.info('Successfully completed bootstrapping')
	except (Exception, KeyboardInterrupt) as e:
		log.exception(e)
		if args.pause_on_error:
			raw_input("Press Enter to commence rollback")
		log.error('Rolling back')

		rollback_tasklist = TaskList()

		def counter_task(task, counter):
			if task in tasklist.tasks_completed and counter not in tasklist.tasks_completed:
				rollback_tasklist.tasks.add(counter)
		rollback_tasklist.load('resolve_rollback_tasks', manifest, counter_task)

		rollback_tasklist.run(info=bootstrap_info, dry_run=args.dry_run)
		log.info('Successfully completed rollback')
Example #6
0
def fetchWallpaper(wallpaperUrl, wallpaperPath):
    try:
        urllib.request.urlretrieve(wallpaperUrl, filename=wallpaperPath)
        return 0
    except Exception as e:
        log.exception(e)
    return 1
Example #7
0
def fetchWallpaper(wallpaperUrl,wallpaperPath):
    try:
        urllib.request.urlretrieve(wallpaperUrl,filename=wallpaperPath)
        return 0
    except Exception as e:
        log.exception(e)
    return 1
Example #8
0
    def check(self, acl, **namespaces):
        """
        Check an ACL rule in the namespaces context.
        """

        try:
            namespace = self.get_namespace(**namespaces)

            result = None
            match = ''

            if isinstance(acl, ACLRule):
                match = repr(acl.rule)
                result = acl.eval(namespace)
            else:
                if self.rules.has_key(acl):
                    for rule in self.rules[acl]:
                        match = repr(rule.rule)
                        if rule.eval(namespace):
                            result = True
                            break
                        else:
                            result = False

            if result is None:
                result = False
                log.info('ACL %s not found' % str(acl))
            else:
                log.info('ACL %s %s %s' % (acl, result, match))
                pass
            return result
        except:
            log.exception('Error while checking ACL %s' % str(acl))
            raise
Example #9
0
 def plottable(ax):
     if ax:
         stock_rsi = TA.STOCHRSI(df).multiply(100)
         rsiPoints = rsi.tail(rsi.shape[0] - 10).apply(
             methods.polarity_shift_rsi)
         rsiPointsGreen = rsiPoints.where(lambda x: x == 1).shift(
             0).dropna().tail(2)
         rsiPointsRed = rsiPoints.where(lambda x: x == -1).shift(
             0).dropna().tail(2)
         pd.concat([rsi, stock_rsi],
                   axis=1).tail(chart_tail_count).plot(figsize=figure_size,
                                                       ax=ax)
         try:
             if rsiPointsRed.shape[0] > 0:
                 ax.scatter(rsiPointsRed.index,
                            rsi[rsiPointsRed.index].values,
                            s=100,
                            c='red')
             if rsiPointsGreen.shape[0] > 0:
                 ax.scatter(rsiPointsGreen.index,
                            rsi[rsiPointsGreen.index].values,
                            s=100,
                            c='green')
         except Exception as e1:
             log.exception(e1)
Example #10
0
    def _connect(self):
        try:
            if(self.dev == ""):
                SerialGamePad.find_serial_devices(self._hardwareID)

                if len(SerialGamePad.devices) > 0:
                    self.dev = SerialGamePad.devices[0]
                    log.info("Using COM Port: %s", self.dev)

            try:
                self._com = serial.Serial(self.dev, timeout=5)
            except serial.SerialException as e:
                ports = SerialGamePad.find_serial_devices(self._hardwareID)
                error = "Invalid port specified. No COM ports available."
                if len(ports) > 0:
                    error = "Invalid port specified. Try using one of: \n" + \
                        "\n".join(ports)
                log.info(error)
                raise SerialPadError(error)

            packet = generate_header(CMDTYPE.INIT, 0)
            self._com.write(packet)

            resp = self._com.read(1)
            if len(resp) == 0:
                SerialGamePad._comError()

            return ord(resp)

        except serial.SerialException as e:
            error = "Unable to connect to the device. Please check that it is connected and the correct port is selected."
            log.exception(e)
            log.error(error)
            raise e
Example #11
0
    def loop(self):
        chan = self.chan
        master_fd = self.master_fd
        fds = [master_fd, chan]
        while master_fd or chan.active:
            try:
                rfds, wfds, xfds = select.select(fds, [], [], 5)
            except:
                log.exception('Exception in PTYWrapper.loop():')
                break

            if master_fd in rfds:
                try:
                    data = pty._read(master_fd)
                except OSError:
                    break
                if data == '':
                    break
                chan.send(data)
            if chan in rfds:
                data = chan.recv(10240)
                if data == '':
                    break
                pty._writen(master_fd, data)
                if chan.closed or chan.eof_received:
                    del fds[fds.index(chan)]
                    pty._writen(master_fd, '\004')  # CTRL-D
                    continue
Example #12
0
 def loop(self):
     chan = self.chan
     master_fd = self.master_fd
     fds = [master_fd, chan]
     while master_fd or chan.active:
         try:
             rfds, wfds, xfds = select.select(
                     fds, [], [], 5)
         except:
             log.exception('Exception in PTYWrapper.loop():')
             break
         
         if master_fd in rfds:
             try:
                 data = pty._read(master_fd)
             except OSError:
                 break
             if data == '':
                 break
             chan.send(data)
         if chan in rfds:
             data = chan.recv(10240)
             if data == '':
                 break
             pty._writen(master_fd, data)
             if chan.closed or chan.eof_received:
                 del fds[fds.index(chan)]
                 pty._writen(master_fd, '\004') # CTRL-D
                 continue
Example #13
0
def LoadStartUpRules():
    global config_file
    config = xml.dom.minidom.parse(config_file)
    for rule in config.getElementsByTagName("startuprule"):
        action = None
        for child in rule.childNodes:
            if child.nodeType != xml.dom.Node.ELEMENT_NODE:
                continue

            if child.nodeName == "action":
                action = NodeVal(child.firstChild)
            elif child.nodeName == "description":
                description = NodeVal(child.firstChild).encode("utf8")
            else:
                raise Exception("Invalid node in config: %s" % child.nodeName)

        if action is None:
            raise Exception("Action not found")

        log.info("Startup Rule:")
        log.ident()
        log.info("Action: %s" % action)
        log.info("Description: %s" % description)
        log.deident()

        try:
            exec action in rules_nspace
        except Exception, inst:
            log.exception(inst, "Action: %s" % action)
Example #14
0
 def get(self):
     """
 This function to do application health check
 """
     log.debug('/x-tree/FSMonitor.html: invoked')
     try:
         log.info('application health check...')
         host_name = socket.gethostname()
         url = "http://localhost:8086/query"
         querystring = {
             "pretty": "true",
             "db": "IOT",
             "q": "SELECT count(*) FROM \"ttd_devices\" "
         }
         response = requests.request("GET", url, params=querystring)
         D = json.loads(response.text)
         total_recs = str(max(
             D['results'][0]['series'][0]['values'][0][1:]))
     except:
         result = {}
         log.exception('Exception while doing HealthCheck')
         return Response('<html><body>THE SERVER IS DOWN</body></html>',
                         mimetype="text/html",
                         status=500)
     return Response('<html><body>INFLUX DB <p/> Count:' + total_recs +
                     '</body></html>',
                     mimetype="text/html")
Example #15
0
def var_func_names(string, ignore=""):
    print("var_func_names(string, ignore=""): ", string, " ,", ignore)
    regex = "[^*/+\-%^()=\[\];,." + ignore + "]+"
    values = re.findall(regex, string)
    for value in values:
        if not value.isalpha() and not re.match("[\d.]", value):
            log.exception("This is not a valid function or variable name: " + value)
Example #16
0
    def check(self, acl, **namespaces):
        """
        Check an ACL rule in the namespaces context.
        """

        try:
            namespace = self.get_namespace(**namespaces)

            result = None
            match = ''

            if isinstance(acl, ACLRule):
                match = repr(acl.rule)
                result = acl.eval(namespace)
            else:
                if self.rules.has_key(acl):
                    for rule in self.rules[acl]:
                        match = repr(rule.rule)
                        if rule.eval(namespace):
                            result = True
                            break
                        else:
                            result = False

            if result is None:
                result = False
                log.info('ACL %s not found' % str(acl))
            else:
                log.info('ACL %s %s %s' % (acl, result, match))
                pass
            return result
        except:
            log.exception('Error while checking ACL %s' % str(acl))
            raise
Example #17
0
def telegram_poller():
    """ 
    - continuously listen to the messages on the telegram chat
    - create tasks for the messages
    - submit to the thread pool
    - wait 3 seconds and re-do the same
    """
    threading.current_thread().setName("Telegram")
    try:
        log.info("Starting Telegram Poller")
        while True:
            last_updated_id = db.config(Const.TELEGRAM_UPDATE_ID)
            msgs = app.get_messages(last_updated_id, timeout=15)

            for message in msgs:
                current_time = int(time.time())
                message.source = "telegram"

                # Don't process Old messages
                last_updated_id = message.update_id
                if not message['text'] or message.date and message.date < (
                        current_time - 11):
                    log.info('discarding: %s ', message)
                    db.set_config(Const.TELEGRAM_UPDATE_ID,
                                  last_updated_id + 1)
                    continue

                db.set_config(Const.TELEGRAM_UPDATE_ID, last_updated_id + 1)
                processor.process_message(message)

    except Exception as e1:
        log.exception(e1)
        app.send_msg("Error occured !", accessControl.adminChatId)
Example #18
0
def run(manifest, debug=False, pause_on_error=False, dry_run=False):
    """Runs the bootstrapping process

    :params Manifest manifest: The manifest to run the bootstrapping process for
    :params bool debug: Whether to turn debugging mode on
    :params bool pause_on_error: Whether to pause on error, before rollback
    :params bool dry_run: Don't actually run the tasks
    """
    import logging

    log = logging.getLogger(__name__)
    # Get the tasklist
    from tasklist import load_tasks
    from tasklist import TaskList
    log.info('Generating tasklist')
    tasks = load_tasks('resolve_tasks', manifest)
    tasklist = TaskList(tasks)
    # 'resolve_tasks' is the name of the function to call on the provider and plugins

    # Create the bootstrap information object that'll be used throughout the bootstrapping process
    from bootstrapinfo import BootstrapInformation
    bootstrap_info = BootstrapInformation(manifest=manifest, debug=debug)

    try:
        # Run all the tasks the tasklist has gathered
        tasklist.run(info=bootstrap_info, dry_run=dry_run)
        # We're done! :-)
        log.info('Successfully completed bootstrapping')
    except (Exception, KeyboardInterrupt) as e:
        # When an error occurs, log it and begin rollback
        log.exception(e)
        if pause_on_error:
            # The --pause-on-error is useful when the user wants to inspect the volume before rollback
            raw_input('Press Enter to commence rollback')
        log.error('Rolling back')

        # Create a useful little function for the provider and plugins to use,
        # when figuring out what tasks should be added to the rollback list.
        def counter_task(taskset, task, counter):
            """counter_task() adds the third argument to the rollback tasklist
            if the second argument is present in the list of completed tasks

            :param set taskset: The taskset to add the rollback task to
            :param Task task: The task to look for in the completed tasks list
            :param Task counter: The task to add to the rollback tasklist
            """
            if task in tasklist.tasks_completed and counter not in tasklist.tasks_completed:
                taskset.add(counter)

        # Ask the provider and plugins for tasks they'd like to add to the rollback tasklist
        # Any additional arguments beyond the first two are passed directly to the provider and plugins
        rollback_tasks = load_tasks('resolve_rollback_tasks', manifest, tasklist.tasks_completed, counter_task)
        rollback_tasklist = TaskList(rollback_tasks)

        # Run the rollback tasklist
        rollback_tasklist.run(info=bootstrap_info, dry_run=dry_run)
        log.info('Successfully completed rollback')
        raise
    return bootstrap_info
Example #19
0
 def unmap(self):
     if self._mapped:
         log.debug('Unmapping window %d', self._wid)
         try:
             self._conn.core.UnmapWindow(self._wid, True).check()
         except Exception:
             log.exception('Error in `unmap` method')
         self._mapped = False
Example #20
0
 def update(self, data_entry):
     self._data_entries.append(data_entry)
     try:
         # operate when there is enough data (3)
         if len(self._data_entries) == self._data_entries.maxlen: 
             self._execute()
     except Exception as e:
         log.exception("%s" % e)
Example #21
0
 def map(self):
     if not self._mapped:
         log.debug('Mapping window %d', self._wid)
         try:
             self._conn.core.MapWindow(self._wid, True).check()
         except Exception:
             log.exception('Error in `map` method')
         self._mapped = True
Example #22
0
 def getCacheObject(self, key):
   
   try:
     data = self.redis.get(key)
     if data is not None: return pickle.loads(self.redis.get(key))
   except Exception as e:
     exception(e)
   
   return None
Example #23
0
def run(opts):
    """Runs the bootstrapping process

	:params dict opts: Dictionary of options from the commandline
	"""
    # Load the manifest
    from manifest import Manifest
    manifest = Manifest(opts['MANIFEST'])

    # Get the tasklist
    from tasklist import load_tasks
    from tasklist import TaskList
    tasks = load_tasks('resolve_tasks', manifest)
    tasklist = TaskList(tasks)
    # 'resolve_tasks' is the name of the function to call on the provider and plugins

    # Create the bootstrap information object that'll be used throughout the bootstrapping process
    from bootstrapinfo import BootstrapInformation
    bootstrap_info = BootstrapInformation(manifest=manifest,
                                          debug=opts['--debug'])

    try:
        # Run all the tasks the tasklist has gathered
        tasklist.run(info=bootstrap_info, dry_run=opts['--dry-run'])
        # We're done! :-)
        log.info('Successfully completed bootstrapping')
    except (Exception, KeyboardInterrupt) as e:
        # When an error occurs, log it and begin rollback
        log.exception(e)
        if opts['--pause-on-error']:
            # The --pause-on-error is useful when the user wants to inspect the volume before rollback
            raw_input('Press Enter to commence rollback')
        log.error('Rolling back')

        # Create a useful little function for the provider and plugins to use,
        # when figuring out what tasks should be added to the rollback list.
        def counter_task(taskset, task, counter):
            """counter_task() adds the second argument to the rollback tasklist
			if the first argument is present in the list of completed tasks

			:param set taskset: The taskset to add the rollback task to
			:param Task task: The task to look for in the completed tasks list
			:param Task counter: The task to add to the rollback tasklist
			"""
            if task in tasklist.tasks_completed and counter not in tasklist.tasks_completed:
                taskset.add(counter)

        # Ask the provider and plugins for tasks they'd like to add to the rollback tasklist
        # Any additional arguments beyond the first two are passed directly to the provider and plugins
        rollback_tasks = load_tasks('resolve_rollback_tasks', manifest,
                                    tasklist.tasks_completed, counter_task)
        rollback_tasklist = TaskList(rollback_tasks)

        # Run the rollback tasklist
        rollback_tasklist.run(info=bootstrap_info, dry_run=opts['--dry-run'])
        log.info('Successfully completed rollback')
        raise e
Example #24
0
def main(argv=sys.argv):
    try:
        bootstrap(argv)
    except SystemExit:
        raise
    except BaseException as ex:
        log.error(str(ex), log.INFRA)
        log.exception(ex)
        sys.exit(1)
Example #25
0
    def getCacheObject(self, key):

        try:
            data = self.redis.get(key)
            if data is not None: return pickle.loads(self.redis.get(key))
        except Exception as e:
            exception(e)

        return None
Example #26
0
    def it_can_include_exceptions(expect, caplog):
        try:
            print(1 / 0)
        except ZeroDivisionError:
            log.exception("exception")

        expect(caplog.text).contains('Traceback ')
        expect(caplog.text).contains('test_records.py", line 34, ')
        expect(caplog.text).contains('ZeroDivisionError')
Example #27
0
 def default_call_handler(self, _name, _chan, *args, **kw):
     func = getattr(self, 'rq_' + _name, None)
     if not func:
         try:
             raise AttributeError('Monitor.rq_%s does not exist' % _name)
         except AttributeError:
             log.exception('in Monitor.default_call_handler')
         return _(u'%s does not exist') % _name
     return func(_chan, *args, **kw)
Example #28
0
def run(args):
    """Runs the bootstrapping process

	Args:
		args (dict): Dictionary of arguments from the commandline
	"""
    # Load the manifest
    from manifest import Manifest
    manifest = Manifest(args.manifest)

    # Get the tasklist
    from tasklist import TaskList
    tasklist = TaskList()
    # 'resolve_tasks' is the name of the function to call on the provider and plugins
    tasklist.load('resolve_tasks', manifest)

    # Create the bootstrap information object that'll be used throughout the bootstrapping process
    from bootstrapinfo import BootstrapInformation
    bootstrap_info = BootstrapInformation(manifest=manifest, debug=args.debug)

    try:
        # Run all the tasks the tasklist has gathered
        tasklist.run(info=bootstrap_info, dry_run=args.dry_run)
        # We're done! :-)
        log.info('Successfully completed bootstrapping')
    except (Exception, KeyboardInterrupt) as e:
        # When an error occurs, log it and begin rollback
        log.exception(e)
        if args.pause_on_error:
            # The --pause-on-error is useful when the user wants to inspect the volume before rollback
            raw_input('Press Enter to commence rollback')
        log.error('Rolling back')

        # Create a new tasklist to gather the necessary tasks for rollback
        rollback_tasklist = TaskList()

        # Create a useful little function for the provider and plugins to use,
        # when figuring out what tasks should be added to the rollback list.
        def counter_task(task, counter):
            """counter_task() adds the second argument to the rollback tasklist
			if the first argument is present in the list of completed tasks

			Args:
				task (Task): The task to look for in the completed tasks list
				counter (Task): The task to add to the rollback tasklist
			"""
            if task in tasklist.tasks_completed and counter not in tasklist.tasks_completed:
                rollback_tasklist.tasks.add(counter)

        # Ask the provider and plugins for tasks they'd like to add to the rollback tasklist
        # Any additional arguments beyond the first two are passed directly to the provider and plugins
        rollback_tasklist.load('resolve_rollback_tasks', manifest,
                               counter_task)

        # Run the rollback tasklist
        rollback_tasklist.run(info=bootstrap_info, dry_run=args.dry_run)
        log.info('Successfully completed rollback')
Example #29
0
def fetchElementTree(xmlUrl):
    et = None
    try:
        log.info('Connect to %s to fetch XML' % xmlUrl)
        response = urllib.request.urlopen(xmlUrl,timeout=5)
        et = xml.etree.ElementTree.fromstring(response.read())
    except Exception as e:
        log.exception(e)
    return et
Example #30
0
def fetchElementTree(xmlUrl):
    et = None
    try:
        log.info('Connect to %s to fetch XML' % xmlUrl)
        response = urllib.request.urlopen(xmlUrl, timeout=5)
        et = xml.etree.ElementTree.fromstring(response.read())
    except Exception as e:
        log.exception(e)
    return et
Example #31
0
def run(opts):
	"""Runs the bootstrapping process

	Args:
		opts (dict): Dictionary of options from the commandline
	"""
	# Load the manifest
	from manifest import Manifest
	manifest = Manifest(opts['MANIFEST'])

	# Get the tasklist
	from tasklist import TaskList
	tasklist = TaskList()
	# 'resolve_tasks' is the name of the function to call on the provider and plugins
	tasklist.load('resolve_tasks', manifest)

	# Create the bootstrap information object that'll be used throughout the bootstrapping process
	from bootstrapinfo import BootstrapInformation
	bootstrap_info = BootstrapInformation(manifest=manifest, debug=opts['--debug'])

	try:
		# Run all the tasks the tasklist has gathered
		tasklist.run(info=bootstrap_info, dry_run=opts['--dry-run'])
		# We're done! :-)
		log.info('Successfully completed bootstrapping')
	except (Exception, KeyboardInterrupt) as e:
		# When an error occurs, log it and begin rollback
		log.exception(e)
		if opts['--pause-on-error']:
			# The --pause-on-error is useful when the user wants to inspect the volume before rollback
			raw_input('Press Enter to commence rollback')
		log.error('Rolling back')

		# Create a new tasklist to gather the necessary tasks for rollback
		rollback_tasklist = TaskList()

		# Create a useful little function for the provider and plugins to use,
		# when figuring out what tasks should be added to the rollback list.
		def counter_task(task, counter):
			"""counter_task() adds the second argument to the rollback tasklist
			if the first argument is present in the list of completed tasks

			Args:
				task (Task): The task to look for in the completed tasks list
				counter (Task): The task to add to the rollback tasklist
			"""
			if task in tasklist.tasks_completed and counter not in tasklist.tasks_completed:
				rollback_tasklist.tasks.add(counter)
		# Ask the provider and plugins for tasks they'd like to add to the rollback tasklist
		# Any additional arguments beyond the first two are passed directly to the provider and plugins
		rollback_tasklist.load('resolve_rollback_tasks', manifest, counter_task)

		# Run the rollback tasklist
		rollback_tasklist.run(info=bootstrap_info, dry_run=opts['--dry-run'])
		log.info('Successfully completed rollback')
		raise e
Example #32
0
File: SNet.py Project: ben-31/zwapi
def netServ():
    try:
        N.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        N.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                          1)  # this is not to have "Addres is already in use"
        N.sock.bind((N.host, N.port))
        N.sock.listen(10)
    except Exception, inst:
        log.exception(inst, "Can not configure port")
        os._exit(0)
Example #33
0
    def start(self):
        # start transport for the client
        self.transport = paramiko.Transport(self.client)
        self.transport.set_log_channel("paramiko")
        # debug !!
        #self.transport.set_hexdump(1)
    
        try:
            self.transport.load_server_moduli()
        except:
            raise
    
        self.transport.add_server_key(self.host_key)
    
        # start the server interface
        negotiation_ev = threading.Event()

        self.init_subsystems()

        self.transport.start_server(negotiation_ev, self)

        while not negotiation_ev.isSet():
            negotiation_ev.wait(0.5)
        if not self.transport.is_active():
            raise 'SSH negotiation failed'

        chan = self.transport.accept(60)
        if chan is None:
            log.error('cannot open the channel. '
                      'Check the transport object. Exiting..')
            return
        log.info('Authenticated %s', self.username)
        self.event.wait(15)
        if not self.event.isSet():
            log.error('client never asked for a shell or a command.'
                        ' Exiting.')
            sys.exit(1)

        self.set_channel(chan)
        namespace = self.monitor.call('get_namespace')
        self.dispatcher = Dispatcher(self.monitor, namespace)
        
        try:
            try:
                # this is the entry point after initialization have been done
                self.do_work()
                # after this point, client is disconnected
            except SSHProxyError, msg:
                log.exception(msg)
                chan.send(chanfmt(str(msg)+'\n'))
            except Exception, msg:
                log.exception("An error occured: %s" % msg)
                chan.send(chanfmt(_(u"An error occured: %s\n") % msg))
Example #34
0
def step(sleep=True, external=True):
    """Do one step forward in the main loop. First all timers are
	checked for expiration and if necessary the associated callback
	function is called. After that the timer list is searched for the
	next timer that will expire. This will define the maximum timeout
	for the following poll statement evaluating the registered
	sockets. Returning from the pool statement the callback functions
	from the sockets reported by the poll system call are invoked. As a
	final task in a notifier step all registered external dispatcher
	functions are invoked."""

    global __in_step, __step_depth, __step_depth_max, __min_timer, _options

    __in_step = True
    __step_depth += 1

    try:
        if __step_depth > __step_depth_max:
            log.exception('maximum recursion depth reached')
            raise NotifierException('error: maximum recursion depth reached')

        # get minInterval for max timeout
        timeout = None
        if not sleep:
            timeout = 0
        else:
            now = int(time() * 1000)
            for interval, timestamp, callback in __timers.values():
                if not timestamp:
                    # timer is blocked (recursion), ignore it
                    continue
                nextCall = timestamp - now
                if timeout is None or nextCall < timeout:
                    if nextCall > 0:
                        timeout = nextCall
                    else:
                        timeout = 0
                        break
            if __min_timer and (__min_timer < timeout or timeout is None):
                timeout = __min_timer

        # wait for event
        fds = []
        if __sockets[IO_READ] or __sockets[IO_WRITE] or __sockets[IO_EXCEPT]:
            try:
                fds = __poll.poll(timeout)
            except select.error, e:
                log.error('error: poll system call interrupted: %s' % str(e))
                if not _options['catch_select_errors']:
                    raise
        elif timeout:
            time_sleep(timeout / 1000.0)
Example #35
0
def step( sleep = True, external = True ):
	"""Do one step forward in the main loop. First all timers are
	checked for expiration and if necessary the associated callback
	function is called. After that the timer list is searched for the
	next timer that will expire. This will define the maximum timeout
	for the following poll statement evaluating the registered
	sockets. Returning from the pool statement the callback functions
	from the sockets reported by the poll system call are invoked. As a
	final task in a notifier step all registered external dispatcher
	functions are invoked."""

	global __in_step, __step_depth, __step_depth_max, __min_timer, _options

	__in_step = True
	__step_depth += 1

	try:
		if __step_depth > __step_depth_max:
			log.exception( 'maximum recursion depth reached' )
			raise NotifierException( 'error: maximum recursion depth reached' )

		# get minInterval for max timeout
		timeout = None
		if not sleep:
			timeout = 0
		else:
			now = int( time() * 1000 )
			for interval, timestamp, callback in __timers.values():
				if not timestamp:
					# timer is blocked (recursion), ignore it
					continue
				nextCall = timestamp - now
				if timeout == None or nextCall < timeout:
					if nextCall > 0:
						timeout = nextCall
					else:
						timeout = 0
						break
			if __min_timer and ( __min_timer < timeout or timeout is None ):
				timeout = __min_timer

		# wait for event
		fds = []
		if __sockets[ IO_READ ] or __sockets[ IO_WRITE ] or __sockets[ IO_EXCEPT ]:
			try:
				fds = __poll.poll( timeout )
			except select.error, e:
				log.error( 'error: poll system call interrupted: %s' % str( e ) )
				if not _options[ 'catch_select_errors' ]:
					raise
		elif timeout:
			time_sleep( timeout / 1000.0 )
Example #36
0
 def _run(self):
     while True:
         asyncResult, handler, args, kwargs = self._queue.get()
         try:
             result = handler(*args, **kwargs)
             asyncResult.set(result)
         except BaseException as e:
             if isinstance(e, GreenletExit):
                 asyncResult.set(None)
                 break
             else:
                 asyncResult.set_exception(e)
                 log.exception()
Example #37
0
    def call(self, _name, _chan, *args, **kw):
        func = getattr(self, self.call_prefix + _name, None)
        try:
            if func:
                return func(_chan, *args, **kw)
            elif getattr(self, 'default_call_handler', None):
                return self.default_call_handler(_name, _chan, *args, **kw)
        except:
            log.exception("An exception occured in IPCInterface.call():")
            return ("Something wrong happened. " +
                    "Please contact the administrator.")

        return "%s does not exist" % _name
Example #38
0
def init_plugins():
  try:
    for plugin in enabled_plugins:
        if plugin in available_plugins.keys():
            try:
                available_plugins[plugin].init()
                log.info('Initialized plugin %s' % available_plugins[plugin].name)
                loaded_plugins[plugin] = available_plugins[plugin]
            except Exception, msg:
                log.exception('init_plugins: plugin %s failed to load (%s)'
                                                        % (plugin, msg))
  except:
      log.exception("init_plugins:")
Example #39
0
    def call(self, _name, _chan, *args, **kw):
        func = getattr(self, self.call_prefix + _name, None)
        try:
            if func:
                return func(_chan, *args, **kw)
            elif getattr(self, 'default_call_handler', None):
                return self.default_call_handler(_name, _chan, *args, **kw)
        except:
            log.exception("An exception occured in IPCInterface.call():")
            return ("Something wrong happened. " +
                                    "Please contact the administrator.")

        return "%s does not exist" % _name
Example #40
0
def start(title, methods):
    """Start the application and handle exceptions."""
    args = parse_args(title, methods)
    log.initialize(args.pop('verbose'))
    try:
        function = args.pop('function')
        log.debug('Starting %s with %s', function.__name__, args)
        function(**args)
        log.debug('Execution finish')
    except AssertionError as error:
        log.error(error)
    except Exception as error:
        log.exception(error)
Example #41
0
def check(username: str, browser: str, debug: bool):
    with get_browser(browser) as b:
        try:
            commands.check(b, username, display=click.echo)
        except Exception as e:  # pylint: disable=broad-except
            if debug:
                import ipdb  # pylint: disable=import-outside-toplevel

                log.exception(e)

                ipdb.post_mortem()
            else:
                raise e from None
Example #42
0
    def _run(self, *args, **kwargs):
        while not self._isNeedStop:
            try:
                gevent.sleep(self._seconds)

                self._isRunning = True
                self._handler(*args, **kwargs)
                self._isRunning = False
            except gevent.hub.GreenletExit:
                pass
            except:
                import log
                log.exception('tick is exception')
Example #43
0
def init_plugins():
    try:
        for plugin in enabled_plugins:
            if plugin in loaded_plugins.keys():
                try:
                    loaded_plugins[plugin].init()
                    log.info('Initialized plugin %s' %
                             loaded_plugins[plugin].name)
                except Exception, msg:
                    log.exception(
                        'init_plugins: plugin %s failed to load (%s)' %
                        (plugin, msg))
    except:
        log.exception("init_plugins:")
Example #44
0
 def kill_zombies(self, signum=None, frame=None):
     try:
         pid, status = os.waitpid(-1, os.WNOHANG)
         if pid and pid in self.children and pid != os.getpid():
             ipc = self.children[pid]['ipc']
             try:
                 del self.children[pid]
                 del self.fds[ipc]
             except KeyError:
                 log.exception("Monitor.kill_zombies():")
                 pass
             log.info("A child process has been killed and cleaned.")
     except OSError:
         pass
Example #45
0
def loadCanteraFile(filepath):
	"""Load a Cantera input (.cti) file. Returns a CoreEdgeReactionModel"""
	import os
	logging.info("Loading Cantera file %s"%filepath)
	logging.debug("which is located at %s"%os.path.abspath(filepath))
	base = os.path.basename(filepath)
	root, ext = os.path.splitext(base)
	cti.dataset(root)
	assert not _species, "Problem: There's already cantera species info in memory."
	try:
		execfile(filepath)
	except NameError, error: # python 2.5 syntax
		logging.exception("RMG's cantera interpreter can't read this cti file."
			+ error.message.lstrip('name '))
		raise	 
Example #46
0
def main(args):
    entries = load_history(os.path.abspath(args.history))

    watcher = ClipboardWatcher(entries)
    watcher.start()
    while True:
        try:
            print("Waiting for changed clipboard...")
            time.sleep(10)
        except KeyboardInterrupt:
            cleanup(watcher, entries, args)
            sys.exit(0)
        except:
            log.exception("An exception occurred during processing")
            cleanup(watcher, entries, args)
            sys.exit(1)
Example #47
0
	def load(self, path):
		"""
		Parse an RMG database library located at `path`.
		"""
		lines = []
		
		# Process the library
		try:
			flib = open(path, 'r')
			for line in flib:
				line = removeCommentFromLine(line).strip()
				if len(line) > 0:
					lines.append(line)
					
		except IOError, e:
			logging.exception('Database library file "' + e.filename + '" not found.')
Example #48
0
	def load(self, path):
		"""
		Parse an RMG database dictionary located at path. An RMG
		dictionary is a list of key-value pairs of a string	label and a string
		record. Each record is separated by at least one empty line.
		"""
		
		# The current record
		record = ''
		
		fdict=None
		# Process the dictionary
		try:
			fdict = open(path, 'r')
			for line in fdict:
				
				line = removeCommentFromLine(line).strip()
				
				# If at blank line, end of record has been found
				if len(line) == 0 and len(record) > 0:
					
					# Label is first line of record
					lines = record.splitlines()
					label = lines[0]
			
					# Add record to dictionary
					self[label] = record
					
					# Clear record in preparation for next iteration
					record = ''
					
				# Otherwise append line to record (if not empty)
				elif len(line) > 0:
					record += line + '\n'
			
			# process the last record! (after end of for loop)
			# Label is first line of record
			if record:
				lines = record.splitlines()
				label = lines[0]
				# Add record to dictionary
				self[label] = record
			
		except InvalidDatabaseException, e:
			logging.exception(str(e))
			raise
Example #49
0
def load_history(history_conf):
    if os.path.exists(history_conf):
        try:
            history_file = file(history_conf, 'r')
        except:
            log.exception("Couldn't read history file")
            sys.exit(1)

        try:
            history_entries = json.load(history_file)
        except:
            log.exception("An error occurred loading history file")
            sys.exit(1)
    else:
        history_entries = []

    return history_entries
Example #50
0
 def __reginit__(self, client, addr, host_key_file):
     self.client = client
     self.client_addr = addr
     ipc_address = get_config('sshproxy').get('ipc_address',
                                             'sshproxy-control')
     handler = IPCClientInterface(self)
     try:
         self.monitor = ipc.IPCClient(ipc_address, handler=handler)
     except:
         log.exception("Couldn't create IPC channel to monitor")
         raise
     self.host_key = paramiko.DSSKey(filename=host_key_file)
     #self.ip_addr, self.port = client.getsockname()
     self.event = threading.Event()
     self.args = []
     self._remotes = {}
     self.exit_status = -1
Example #51
0
	def load(self, path):
		"""
		Parse an RMG database tree located at `path`. An RMG tree is an 
		n-ary tree representing the hierarchy of items in the dictionary.
		"""

		# An array of parents used when forming the tree
		parents = [None]
		
		import re
		parser = re.compile('^\s*L(?P<level>\d+)\s*:\s*(?P<label>\S+)')
		# should match '  L3 : foo_bar '  and 'L3:foo_bar'
		
		# Process the tree (optional)
		try:
			ftree = open(path, 'r')
			for line in ftree:
				line = removeCommentFromLine(line).strip()
				if len(line) > 0:
					# Extract level
					match = parser.match(line)
					if not match: 
						raise InvalidDatabaseException("Couldn't parse line '%s'"%line.strip() ) 
					level = int(match.group('level'))
					label = match.group('label')
					
					# Find immediate parent of the new node
					parent = None
					if len(parents) < level:
						raise InvalidDatabaseException("Invalid level specified in line '%s'"%line.strip() )
					else:
						while len(parents) > level:
							parents.remove(parents[-1])
						if len(parents) > 0:
							parent = parents[level-1]
					
					# Add node to tree
					self.add(label, parent)
					
					# Add node to list of parents
					parents.append(label)
					
								
		except InvalidDatabaseException, e:
			logging.exception(str(e))
 def _mainloop(self):   
     response_handlers = {
             'joined': self._game_joined,
             'gameStarted': self._game_started,
             'gameIsOn': self._make_move,
             'gameIsOver': self._game_over
             }
     response = ""
     while True:
         try:
             response = self._connection.receive()
             msg_type, data = response['msgType'], response['data']
             if response_handlers.has_key(msg_type):
                 response_handlers[msg_type](data)
             else:
                 log.warning('Invalid Message received: %s' % response) 
         except:
             log.exception('Json data: %s' % response) 
Example #53
0
def bind_server(daemon):
    conf = get_config('sshproxy')
    # preserve compatibility with 0.4.* (bindip)
    ip = conf['listen_on'] or conf.get('bindip', '')
    port = conf['port']

    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind((ip, port))
        sock.listen(100)
        if not daemon:
            print "Server ready, clients may login now ..."
        log.debug('Listening for connection ...')
    except Exception, e:
        log.exception("ERROR: Couldn't bind on port %s" % port)
        print "ERROR: Couldn't bind on port %s" % port
        sys.exit(1)
Example #54
0
	def get_open_ports(self):
		log.log('get_open_ports function called')
		
		ports = []

		try:
			soc_family = socket.getaddrinfo('%s.asterix.cz' % self.mj, 0)[0][0]
		except:
			log.exception('socket.getaddrinfo exception')
			soc_family = None
		#endtry

		if self.mj in self.cemex:
			log.info('cemex')

			f = os.popen('nmap -Pn -p 22,3389,5900 %s' % self.cemex[self.mj])
		elif soc_family == socket.AF_INET:
			log.info('IPv4')

			f = os.popen('nmap -Pn -p 22,3389,5900 %s.asterix.cz' % self.mj)
		elif soc_family == socket.AF_INET6:
			log.info('IPv6')

			f = os.popen('nmap -6 -Pn -p 22,3389,5900 %s.asterix.cz' % self.mj)
		else:
			log.error('unknown address family: %s' % soc_family)
			return ports
		#endif

		for l in f.read().split('\n'):
			log.info(l)
		
			if '22/tcp' in l and 'open' in l:
				ports.append('22')
			elif '3389/tcp' in l and 'open' in l:
				ports.append('3389')
			elif '5900/tcp' in l and 'open' in l:
				ports.append('5900')
			#endif
		#endfor
		
		return ports
Example #55
0
def get_servers_all_regions(image_id=None, all_tenants=True):
    servers = []
    try:
        session, catalog = get_admin_session()
        token = session.get_token()
    except Exception as e:
        log.exception('Failed to get token from keystone: %s' % str(e))
        return []

    kwargs = {'headers': {}, 'params': {}}
    kwargs['timeout'] = 30
    if all_tenants:
        kwargs['params']['all_tenants'] = True
    if image_id:
        kwargs['params']['image'] = image_id
    kwargs['headers']['X-Auth-Token'] = token
    kwargs['headers']['Content-Type'] = 'application/json'
    http = requests.Session()

    for region in REGIONS:
        nova_url = ''
        nova_catalog = [res for res in catalog
                        if res['type'] == 'compute'
                        and res['endpoints'][0]['region'] == region]
        for res in nova_catalog:
            for r in res['endpoints']:
                if r['interface'] == 'public':
                    nova_url = r['url']
                    break
        if not nova_url:
            return {'servers': {}}
        try:
            kwargs['headers']['X-Openstack-Region'] = region
            resp = http.request('GET', nova_url + \
                '/servers/detail', **kwargs)
            for server in resp.json()['servers']:
                server['region'] = region
                servers.append(server)
        except Exception, e:
            log.error('Failed to get servers in region of %s' % region)
            continue