def do_import(self):
        """Handle import files or streams passed with '-i'."""
        tmp_import = None
        try:
            if self.args[0].startswith('@') and self.args[0] != '@-':
                import_file = os.path.expanduser(self.args[0][1:])
                if not os.path.isfile(import_file):
                    self.parser.error("File not found (or not a file): {}".format(import_file))
                args = (xmlrpc.NOHASH, os.path.abspath(import_file))
            else:
                script_text = '\n'.join(self.args + [''])
                if script_text == '@-\n':
                    script_text = sys.stdin.read()

                with tempfile.NamedTemporaryFile(suffix='.rc', prefix='rtxmlrpc-', delete=False) as handle:
                    handle.write(script_text)
                    tmp_import = handle.name
                args = (xmlrpc.NOHASH, tmp_import)

            self.execute(self.open(), 'import', args)
        finally:
            if tmp_import and os.path.exists(tmp_import):
                os.remove(tmp_import)
def do_import ( self ) : tmp_import = None try : if self . args [ 0 ] . startswith ( '@' ) and self . args [ 0 ] != '@-' : import_file = os . path . expanduser ( self . args [ 0 ] [ 1 : ] ) if not os . path . isfile ( import_file ) : self . parser . error ( "File not found (or not a file): {}" . format ( import_file ) ) args = ( xmlrpc . NOHASH , os . path . abspath ( import_file ) ) else : script_text = '\n' . join ( self . args + [ '' ] ) if script_text == '@-\n' : script_text = sys . stdin . read ( ) with tempfile . NamedTemporaryFile ( suffix = '.rc' , prefix = 'rtxmlrpc-' , delete = False ) as handle : handle . write ( script_text ) tmp_import = handle . name args = ( xmlrpc . NOHASH , tmp_import ) self . execute ( self . open ( ) , 'import' , args ) finally : if tmp_import and os . path . exists ( tmp_import ) : os . remove ( tmp_import )
Handle import files or streams passed with '-i'.