def stats( self ): """ Print runtime statistics. @return: 0 @rtype: int @todo: the doc-string should mention --machine-readable, but this is currently impossible with interactive help. """ output = [] for instance in self.instances: if not instance.running(): continue try: iq = instance.get_stats() o = [ instance.get_jid() + ':' ] for stat in iq.getQueryChildren(): value = stat.getAttr( 'value' ) unit = stat.getAttr( 'units' ) name = stat.getAttr( 'name' ) o.append( name + ': ' + value + ' ' + unit ) output.append( "\n".join( o ) ) except RuntimeError, e: env.error( "%s: %s"%(instance.get_jid(), e.message) )
def copy(frm, to, filter = common.Filter()): """Perform a copy of a file or a recursive copy of a directory.""" makedir(to) try: if not frm.is_dir(): shutil.copyfile(str(frm), str(to / frm.get_file())) else: parent = frm.parent() for dir, dirs, files in os.walk(str(frm)): # create directory org_dpath = common.Path(dir) tgt_dpath = to / common.Path(dir).relative_to(parent) if not tgt_dpath.exists(): os.mkdir(str(tgt_dpath)) # copy files for file in files: org_fpath = org_dpath / file tgt_fpath = to / common.Path(dir).relative_to(parent) / file if filter.accept(org_fpath): shutil.copyfile(str(org_fpath), str(tgt_fpath)) # copy directories for d in dirs: org_path = org_dpath / d if not filter.accept(org_path): dirs.remove(d) except (IOError, OSError) as e: env.error(str(e))
def execute(self, ctx): try: ctx.print_action(self.signature()) to = self.install_path() lowlevel.copy(self.data.path, to, common.NotFilter(self.discard)) ctx.print_action_success() except common.MaatError as e: msg = str(e) ctx.print_action_failure(msg) env.error("installation failed")
def register( self, jid, username, password=None, language=None, encoding=None ): """ Register the user with JID I{jid} and the legacy network account I{username}. If the users default I{password}, I{language} and I{encoding} are not given, this method will ask for these details interactivly. B{Note:} It does not make sense to register a user across more than one transport, since a I{username} is typically only valid within a single legacy network. This method will return an error if this group currently represents more then one transport. @param jid: The JID of the user to be registered. @type jid: str @param username: The username of the user in the legacy network. @type username: str @param password: The password for the legacy network. @type password: str @param language: The language code used by the user (e.g. 'en'). @type language: str @param encoding: The default character encoding (e.g. 'utf8'). @type encoding: str """ if len( self.instances ) != 1: env.error( "Error: This command can only be executed with a single instance" ) return 1 if not password: import getpass pwd_in = getpass.getpass( "password to remote network: " ) pwd2_in = getpass.getpass( "confirm: " ) if pwd2_in != pwd_in: env.error( "Error: Passwords do not match" ) else: password = pwd_in if not language: language = raw_input( 'Language (default: en): ' ) if language == '': language = 'en' if not encoding: encoding = raw_input( 'Encoding (default: utf8): ' ) if encoding == '': encoding = 'utf8' status = "0" # we don't ask for VIP status for instance in self.instances: args = [ jid, username, password, language, encoding, status ] self._single_action( instance, 'register', args )
def set_vip_status( self, jid, state ): """ Set the VIP status of the user L{jid}. The I{status} should be "0" to disable VIP status and "1" to enable it. @param jid: The JID that should have its status set @type jid: str @param state: The state you want to set. See above for more information. @type state: str """ status_string = "Setting VIP-status for '%s' to " if state == "0": status_string += "False:" elif state == "1": status_string += "True:" else: env.error( "Error: status (third argument) must be either 0 or 1" ) return 1 env.log( status_string%(jid) ) for instance in self.instances: self._single_action( instance, 'set_vip_status', [jid,state] )