def calculate_net_speed(rate, indicator, dt=2, interface=Interfaces.get_default()): t0 = time.time() #loop untill we have a default (enabled) interface while interface is None: interface = Interfaces.get_default() counter = psutil.net_io_counters(pernic=True)[interface] tot = (counter.bytes_sent, counter.bytes_recv) while True: last_tot = tot time.sleep(dt) #cover an edge case, loop untill we have a default (enabled) interface while interface is None: interface = Interfaces.get_default() counter = psutil.net_io_counters(pernic=True)[interface] t1 = time.time() tot = (counter.bytes_sent, counter.bytes_recv) ul, dl = [(now - last) / (t1 - t0) for now, last in zip(tot, last_tot)] rate.append((ul, dl)) update_speed(indicator) t0 = time.time()
def setup(on_startup): '''Setup mining service internal environment. You should not need to change this. If you want to use another Worker manager or Share manager, you should set proper reference to Interfaces class *before* you call setup() in the launcher script.''' from stratum import settings from interfaces import Interfaces # Let's wait until share manager and worker manager boot up (yield Interfaces.share_manager.on_load) (yield Interfaces.worker_manager.on_load) from lib.block_updater import BlockUpdater from lib.template_registry import TemplateRegistry from lib.bitcoin_rpc import BitcoinRPC from lib.block_template import BlockTemplate from lib.coinbaser import SimpleCoinbaser bitcoin_rpc = BitcoinRPC(settings.NOVACOIN_TRUSTED_HOST, settings.NOVACOIN_TRUSTED_PORT, settings.NOVACOIN_TRUSTED_USER, settings.NOVACOIN_TRUSTED_PASSWORD) import stratum.logger log = stratum.logger.get_logger('mining') log.info('Waiting for novacoin RPC...') while True: try: result = (yield bitcoin_rpc.getblocktemplate()) if isinstance(result, dict): log.info('Response from novacoin RPC OK') break except: time.sleep(1) coinbaser = SimpleCoinbaser(bitcoin_rpc, settings.CENTRAL_WALLET) (yield coinbaser.on_load) registry = TemplateRegistry(BlockTemplate, coinbaser, bitcoin_rpc, settings.INSTANCE_ID, MiningSubscription.on_template, Interfaces.share_manager.on_network_block) # Template registry is the main interface between Stratum service # and pool core logic Interfaces.set_template_registry(registry) # Set up polling mechanism for detecting new block on the network # This is just failsafe solution when -blocknotify # mechanism is not working properly BlockUpdater(registry, bitcoin_rpc) log.info("MINING SERVICE IS READY") on_startup.callback(True)
def __init__(self, test_utility, model, serial_manager, report): super().__init__() self.abort_btn = QPushButton("Abort") self.abort_btn.clicked.connect(self.abort) self.setButton(QWizard.CustomButton1, self.abort_btn) self.button(QWizard.FinishButton).clicked.connect(self.finish) qbtn_layout = [ QWizard.Stretch, QWizard.NextButton, QWizard.FinishButton, QWizard.CustomButton1 ] self.setButtonLayout(qbtn_layout) self.button(QWizard.NextButton).setEnabled(False) # This fixes a bug in the default style which hides the QWizard # buttons until the window is resized. self.setWizardStyle(0) setup_id = self.addPage( Setup(self, test_utility, serial_manager, model, report)) program_id = self.addPage( Program(self, test_utility, serial_manager, model, report)) interfaces_id = self.addPage( Interfaces(self, test_utility, serial_manager, model, report)) final_id = self.addPage(FinalPage(self, test_utility, report)) self.setup_page = self.page(setup_id) self.program_page = self.page(program_id) self.interfaces_page = self.page(interfaces_id) self.final_page = self.page(final_id) self.tu = test_utility self.report = report
def __init__(self, model): super(Network, self).__init__(model, None) self.role_key = "administration" self.admin_methods = ['PUT'] self.interfaces = Interfaces(model) self.uri_fmt = '/network/%s' self.update_params = ['nameservers', 'gateway'] self.confirm_change = self.generate_action_handler('confirm_change')
def __init__(self, model): super(Network, self).__init__(model, None) self.admin_methods = ['PUT', 'POST'] self.interfaces = Interfaces(model) self.cfginterfaces = Cfginterfaces(model) self.uri_fmt = '/network/%s' self.update_params = ['nameservers', 'gateway'] self.confirm_change = self.generate_action_handler('confirm_change') self.log_map = NETWORK_REQUESTS
def interfaces(s): ''' A collection of all of the network interfaces for a particular nodegroup. ''' center('Nodegroup.interfaces') retval = Interfaces(s.__maas, s['uuid']) center('Nodegroup.interfaces') return retval
def __init__(self, root): self.app = root self.indicator = appindicator.Indicator.new( self.app.name, "", appindicator.IndicatorCategory.APPLICATION_STATUS) self.indicator.set_status (appindicator.IndicatorStatus.ACTIVE) self.indicator.set_label(self.DEFAULT_LABEL, self.INDICATOR_LABEL_GUIDE ) self.main_menu = Gtk.Menu() main_menu_item = Gtk.MenuItem() main_menu_item.set_label("Settings") self.main_menu.append(main_menu_item) #settings sub menu settings_submenu = Gtk.Menu() interfaces = Gtk.MenuItem() interfaces.set_label("Interfaces") settings_submenu.append(interfaces) available_interfaces = Interfaces.get_interfaces() interfaces_submenu = Gtk.Menu() for i in available_interfaces: if i not in "lo": interfaces_submenu_item = Gtk.MenuItem() interfaces_submenu_item.set_label(i) interfaces_submenu.append(interfaces_submenu_item) interfaces.set_submenu(interfaces_submenu) settings_submenu_item = Gtk.MenuItem() settings_submenu_item.set_label("Units") settings_submenu.append(settings_submenu_item) main_menu_item.set_submenu(settings_submenu) main_menu_item = Gtk.MenuItem() main_menu_item.set_label("Exit") main_menu_item.connect("activate", self.cb_exit, '') self.main_menu.append(main_menu_item) #show menu items self.main_menu.show_all() #set menu to indicator self.indicator.set_menu(self.main_menu)
def refresh(self): self.__log.info('Refreshing') try: previous = self.selected_interface.name except AttributeError: previous = None # Rebuild the dictionary of interfaces and the menu self.interfaces = Interfaces(self.settings.url) self._create_menu() # Select previously selected interface again if self.interfaces.has_interface(previous): self.__log.debug('Using previously selected interface %s', previous) self._menu_items[previous].select() else: self.__log.debug( 'Previously selected interface %s no longer exists, using public', previous) self._menu_items[interface.PUBLIC].select() self.update()
log.info('Connected to litecoind - Ready to GO!') # Start the coinbaser coinbaser = SimpleCoinbaser(bitcoin_rpc, getattr(settings, 'CENTRAL_WALLET')) (yield coinbaser.on_load) registry = TemplateRegistry(BlockTemplate, coinbaser, bitcoin_rpc, getattr(settings, 'INSTANCE_ID'), MiningSubscription.on_template, Interfaces.share_manager.on_network_block) # Template registry is the main interface between Stratum service # and pool core logic Interfaces.set_template_registry(registry) # Set up polling mechanism for detecting new block on the network # This is just failsafe solution when -blocknotify # mechanism is not working properly BlockUpdater(registry, bitcoin_rpc) log.info("MINING SERVICE IS READY") on_startup.callback(True)
log.info('Starting registry') mining_subscription = MiningSubscription() mining_subscription.wallet = wallet registry = TemplateRegistry(wallet, BlockTemplate, coinbaser, bitcoin_rpc, getattr(settings, 'INSTANCE_ID'), mining_subscription.on_template, Interfaces.share_manager.on_network_block) log.info('Set template registry for %s' % wallet) # Template registry is the main interface between Stratum service # and pool core logic #Interfaces.set_template_registry(registry) Interfaces.add_template_registry(wallet, registry) log.info('Block updater') # Set up polling mechanism for detecting new block on the network # This is just failsafe solution when -blocknotify # mechanism is not working properly BlockUpdater(wallet, registry, bitcoin_rpc) log.info('Threading thread') prune_thr = threading.Thread(target=WorkLogPruner, args=(Interfaces.worker_manager.job_log, )) prune_thr.daemon = True prune_thr.start()
def setup(on_startup): '''Setup mining service internal environment. You should not need to change this. If you want to use another Worker manager or Share manager, you should set proper reference to Interfaces class *before* you call setup() in the launcher script.''' import lib.settings as settings # Get logging online as soon as possible import lib.logger log = lib.logger.get_logger('mining') from interfaces import Interfaces from lib.block_updater import BlockUpdater from lib.template_registry import TemplateRegistry from lib.bitcoin_rpc import BitcoinRPC from lib.block_template import BlockTemplate from lib.coinbaser import SimpleCoinbaser bitcoin_rpc = BitcoinRPC(settings.DAEMON_TRUSTED_HOST, settings.DAEMON_TRUSTED_PORT, settings.DAEMON_TRUSTED_USER, settings.DAEMON_TRUSTED_PASSWORD) log.info("Connecting to RPC...") while True: try: log.info('Waiting for RPC...') result = (yield bitcoin_rpc.getblocktemplate()) if isinstance(result, dict): break except: time.sleep(1) log.info('Connected to RPC - Ready to GO!') # Start the coinbaser coinbaser = SimpleCoinbaser(bitcoin_rpc, getattr(settings, 'CENTRAL_WALLET')) (yield coinbaser.on_load) registry = TemplateRegistry(BlockTemplate, coinbaser, bitcoin_rpc, getattr(settings, 'INSTANCE_ID'), MiningSubscription.on_template, Interfaces.share_manager.on_network_block) # Template registry is the main interface between Stratum service # and pool core logic Interfaces.set_template_registry(registry) # Set up polling mechanism for detecting new block on the network # This is just failsafe solution when -blocknotify # mechanism is not working properly BlockUpdater(registry, bitcoin_rpc) prune_thr = threading.Thread(target=WorkLogPruner, args=(Interfaces.worker_manager.job_log, )) prune_thr.daemon = True prune_thr.start() log.info("MINING SERVICE IS READY") on_startup.callback(True)
class IPIndicator: """ Updates the label in the indicator bar. Does not refetch current IPs! """ def update(self): self.__log.info('Updating indicator label') self.ind.set_label(self.selected_interface.ip) """ Fetches the current interfaces and their IPs. """ def refresh(self): self.__log.info('Refreshing') try: previous = self.selected_interface.name except AttributeError: previous = None # Rebuild the dictionary of interfaces and the menu self.interfaces = Interfaces(self.settings.url) self._create_menu() # Select previously selected interface again if self.interfaces.has_interface(previous): self.__log.debug('Using previously selected interface %s', previous) self._menu_items[previous].select() else: self.__log.debug( 'Previously selected interface %s no longer exists, using public', previous) self._menu_items[interface.PUBLIC].select() self.update() __log = logging.getLogger(__name__) def __init__(self, settings): self.__log.debug('Initializing %s', self.__class__) dummy_icon = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'images', 'icon.png') self.__log.debug('Loading dummy icon from %s', dummy_icon) self.ind = appindicator.Indicator( "ip-indicator", dummy_icon, appindicator.CATEGORY_APPLICATION_STATUS) self.ind.set_status(appindicator.STATUS_ACTIVE) self.settings = settings self.__log.debug('Settings: %s', vars(settings)) self.settings.sanitize_url() self.selected_interface = None self.refresh() if self.interfaces.has_interface(self.settings.interface): self.__log.debug('Using interface %s from settings', self.settings.interface) self._menu_items[self.settings.interface].select() else: self.__log.debug('Cannot use interface %s from settings', self.settings.interface) self._connect_dbus() def _connect_dbus(self): self.__log.info('Connecting to DBus') DBusGMainLoop(set_as_default=True) system_bus = dbus.SystemBus() system_bus.add_signal_receiver( self._on_dbus_state_changed, 'PropertiesChanged', 'org.freedesktop.NetworkManager.Connection.Active') def _create_menu(self): self.__log.info('Building menu') menu = gtk.Menu() refresh = gtk.MenuItem("Refresh") refresh.connect("activate", self._on_manual_refresh) refresh.show() menu.append(refresh) sep = gtk.SeparatorMenuItem() sep.show() menu.append(sep) # Build the list of interfaces group = None self._menu_items = {} for interface in self.interfaces.interfaces.itervalues(): item = MenuItem(interface) item.selected = self._select_interface if not group: group = item.get_item().get_group()[0] else: item.get_item().set_group(group) menu.append(item.get_item()) self._menu_items[interface.name] = item self.__log.debug('Menu items: %s', self._menu_items) sep = gtk.SeparatorMenuItem() sep.show() menu.append(sep) a = gtk.MenuItem("About") a.connect("activate", self._on_about) a.show() menu.append(a) q = gtk.MenuItem("Quit") q.connect("activate", self._on_quit) q.show() menu.append(q) self.ind.set_menu(menu) def _select_interface(self, menu_item, interface): self.__log.info('Selecting interface: %s', interface.name) self.selected_interface = interface self.update() def _on_dbus_state_changed(self, *args, **kwargs): self.__log.info('DBus state changed') time.sleep(0.3) self.refresh() def _on_manual_refresh(self, widget): self.__log.info('User triggered manual refresh') self.refresh() def _on_quit(self, widget): self.__log.info('=== User clicked Quit ===') gtk.main_quit() def _on_about(self, widget): self.__log.debug('Showing about about box') about = gtk.AboutDialog() about.set_program_name('indicator-ip') about.set_version('Version ' + version.VERSION) about.set_website('https://github.com/bovender/indicator-ip') about.set_authors([ 'DJG (https://github.com/sentientwaffle)', 'Daniel Kraus (https://github.com/bovender)' ]) about.set_copyright('(c) 2012 DJG, 2015 Daniel Kraus') about.set_comments(""" Show the current IP address as indicator. Public IP provider: %s (Change on command line with -u option.) """ % self.settings.url) about.set_license(""" Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.""") response = about.run() about.hide()
def create_interfaces(self): self.logger.info('create interfaces') for key in self.interfaces.keys(): inter = Interfaces(self.interfaces[key][0], self.interfaces[key][1]) inter.setup()
mining_subscription.wallet = wallet registry = TemplateRegistry(wallet, BlockTemplate, coinbaser, bitcoin_rpc, getattr(settings, 'INSTANCE_ID'), mining_subscription.on_template, Interfaces.share_manager.on_network_block) log.info('Set template registry for %s' % wallet) # Template registry is the main interface between Stratum service # and pool core logic #Interfaces.set_template_registry(registry) Interfaces.add_template_registry(wallet, registry) log.info('Block updater') # Set up polling mechanism for detecting new block on the network # This is just failsafe solution when -blocknotify # mechanism is not working properly BlockUpdater(wallet, registry, bitcoin_rpc) log.info('Threading thread') prune_thr = threading.Thread(target=WorkLogPruner, args=(Interfaces.worker_manager.job_log,)) prune_thr.daemon = True prune_thr.start() #on_startup.callback(True)
class IPIndicator: """ Updates the label in the indicator bar. Does not refetch current IPs! """ def update(self): self.__log.info('Updating indicator label') self.ind.set_label(self.selected_interface.ip) """ Fetches the current interfaces and their IPs. """ def refresh(self): self.__log.info('Refreshing') try: previous = self.selected_interface.name except AttributeError: previous = None # Rebuild the dictionary of interfaces and the menu self.interfaces = Interfaces(self.settings.url) self._create_menu() # Select previously selected interface again if self.interfaces.has_interface(previous): self.__log.debug('Using previously selected interface %s', previous) self._menu_items[previous].select() else: self.__log.debug( 'Previously selected interface %s no longer exists, using public', previous) self._menu_items[interface.PUBLIC].select() self.update() __log = logging.getLogger(__name__) def __init__(self, settings): self.__log.debug('Initializing %s', self.__class__) dummy_icon = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'images', 'icon.png') self.__log.debug('Loading dummy icon from %s', dummy_icon) self.ind = appindicator.Indicator( "ip-indicator", dummy_icon, appindicator.CATEGORY_APPLICATION_STATUS) self.ind.set_status(appindicator.STATUS_ACTIVE) self.settings = settings self.__log.debug('Settings: %s', vars(settings)) self.settings.sanitize_url() self.selected_interface = None self.refresh() if self.interfaces.has_interface(self.settings.interface): self.__log.debug('Using interface %s from settings', self.settings.interface) self._menu_items[self.settings.interface].select() else: self.__log.debug('Cannot use interface %s from settings', self.settings.interface) self._connect_dbus() def _connect_dbus(self): self.__log.info('Connecting to DBus') DBusGMainLoop(set_as_default=True) system_bus = dbus.SystemBus() system_bus.add_signal_receiver(self._on_dbus_state_changed, 'PropertiesChanged', 'org.freedesktop.NetworkManager.Connection.Active') def _create_menu(self): self.__log.info('Building menu') menu = gtk.Menu() refresh = gtk.MenuItem("Refresh") refresh.connect("activate", self._on_manual_refresh) refresh.show() menu.append(refresh) sep = gtk.SeparatorMenuItem() sep.show() menu.append(sep) # Build the list of interfaces group = None self._menu_items = {} for interface in self.interfaces.interfaces.itervalues(): item = MenuItem(interface) item.selected = self._select_interface if not group: group = item.get_item().get_group()[0] else: item.get_item().set_group(group) menu.append(item.get_item()) self._menu_items[interface.name] = item self.__log.debug('Menu items: %s', self._menu_items) sep = gtk.SeparatorMenuItem() sep.show() menu.append(sep) a = gtk.MenuItem("About") a.connect("activate", self._on_about) a.show() menu.append(a) q = gtk.MenuItem("Quit") q.connect("activate", self._on_quit) q.show() menu.append(q) self.ind.set_menu(menu) def _select_interface(self, menu_item, interface): self.__log.info('Selecting interface: %s', interface.name) self.selected_interface = interface self.update() def _on_dbus_state_changed(self, *args, **kwargs): self.__log.info('DBus state changed') time.sleep(0.3) self.refresh() def _on_manual_refresh(self, widget): self.__log.info('User triggered manual refresh') self.refresh() def _on_quit(self, widget): self.__log.info('=== User clicked Quit ===') gtk.main_quit() def _on_about(self, widget): self.__log.debug('Showing about about box') about = gtk.AboutDialog() about.set_program_name('indicator-ip') about.set_version('Version ' + version.VERSION) about.set_website('https://github.com/bovender/indicator-ip') about.set_authors([ 'DJG (https://github.com/sentientwaffle)', 'Daniel Kraus (https://github.com/bovender)']) about.set_copyright('(c) 2012 DJG, 2015 Daniel Kraus') about.set_comments(""" Show the current IP address as indicator. Public IP provider: %s (Change on command line with -u option.) """ % self.settings.url) about.set_license(""" Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.""") response = about.run() about.hide()