示例#1
0
文件: rpcserver.py 项目: timypcr/viri
    def rm(self, cert, file_id):
        """Removes a file given its id"""
        import logging
        from libviri.objects import File

        if File.exists(self.db, file_id):
            logging.info('File {} removed'.format(file_id))
            File.delete(self.db, {'file_id': file_id})
            return (SUCCESS, 'File successfully removed')
        else:
            return (ERROR, 'File not found')
示例#2
0
    def rm(self, cert, file_id):
        """Removes a file given its id"""
        import logging
        from libviri.objects import File

        if File.exists(self.db, file_id):
            logging.info('File {} removed'.format(file_id))
            File.delete(self.db, {'file_id': file_id})
            return (SUCCESS, 'File successfully removed')
        else:
            return (ERROR, 'File not found')
示例#3
0
文件: rpcserver.py 项目: timypcr/viri
    def mv(self, cert, file_id, new_file_name):
        """Renames file with the given id"""
        import logging
        from libviri.objects import File

        if File.exists(self.db, file_id):
            logging.info('File {} renamed to {}'.format(
                file_id, new_file_name))
            File.update(self.db, {'file_name': new_file_name},
                        {'file_id': file_id})
            return (SUCCESS, 'File successfully renamed')
        else:
            return (ERROR, 'File not found')
示例#4
0
    def mv(self, cert, file_id, new_file_name):
        """Renames file with the given id"""
        import logging
        from libviri.objects import File

        if File.exists(self.db, file_id):
            logging.info('File {} renamed to {}'.format(file_id, new_file_name))
            File.update(self.db,
                {'file_name': new_file_name},
                {'file_id': file_id})
            return (SUCCESS, 'File successfully renamed')
        else:
            return (ERROR, 'File not found')
示例#5
0
    def ls(self, cert):
        """List files on the database"""
        from libviri.objects import File

        return (SUCCESS, File.query(self.db,
            fields=('file_name', 'file_id', 'saved'),
            order=('saved',)))
示例#6
0
文件: rpcserver.py 项目: timypcr/viri
    def ls(self, cert):
        """List files on the database"""
        from libviri.objects import File

        return (SUCCESS,
                File.query(self.db,
                           fields=('file_name', 'file_id', 'saved'),
                           order=('saved', )))
示例#7
0
    def get(self, cert, file_name_or_id):
        """Returns the content of a file"""
        import xmlrpc.client
        from libviri.objects import File

        try:
            return (SUCCESS, xmlrpc.client.Binary(
                File.get_content(self.db, file_name_or_id)))
        except File.Missing:
            return (ERROR, 'File not found')
示例#8
0
文件: rpcserver.py 项目: timypcr/viri
    def get(self, cert, file_name_or_id):
        """Returns the content of a file"""
        import xmlrpc.client
        from libviri.objects import File

        try:
            return (SUCCESS,
                    xmlrpc.client.Binary(
                        File.get_content(self.db, file_name_or_id)))
        except File.Missing:
            return (ERROR, 'File not found')
示例#9
0
    def put(self, cert, file_name, file_content):
        """Receives a script or a data file from viric, and saves it in the
        viri database. A content hash is used as id, so if the file exists,
        it's not saved again.

        Arguments:
        file_name -- original file name
        file_content -- content of the file processed using
            xmlrpc.client.Binary.encode()
        """
        import logging
        from libviri.objects import File

        logging.info('File {} saved'.format(file_name))
        return (SUCCESS, File.create(self.db,
            dict(file_name=file_name, content=file_content.data)
            )['file_id'])
示例#10
0
文件: rpcserver.py 项目: timypcr/viri
    def put(self, cert, file_name, file_content):
        """Receives a script or a data file from viric, and saves it in the
        viri database. A content hash is used as id, so if the file exists,
        it's not saved again.

        Arguments:
        file_name -- original file name
        file_content -- content of the file processed using
            xmlrpc.client.Binary.encode()
        """
        import logging
        from libviri.objects import File

        logging.info('File {} saved'.format(file_name))
        return (SUCCESS,
                File.create(
                    self.db,
                    dict(file_name=file_name,
                         content=file_content.data))['file_id'])
示例#11
0
文件: rpcserver.py 项目: timypcr/viri
    def execute(self, cert, file_name_or_id, args):
        """Executes a script and returns the script id and the execution
        result, which can be the return of the script in case of success
        or the traceback and error message in case of failure.
        It is possible to execute a script already sent, given its id, or
        to send the script to execute, using the original script file name
        and the script (file) content.
        """
        import traceback
        from libviri.objects import File

        try:
            success, res = File.execute(self.db, file_name_or_id, args,
                                        self.context, cert)
        except File.Missing:
            return (ERROR, 'File not found')
        except:
            return (ERROR, traceback.format_exc())
        else:
            return (SUCCESS if success else ERROR, res)
示例#12
0
    def execute(self, cert, file_name_or_id, args):
        """Executes a script and returns the script id and the execution
        result, which can be the return of the script in case of success
        or the traceback and error message in case of failure.
        It is possible to execute a script already sent, given its id, or
        to send the script to execute, using the original script file name
        and the script (file) content.
        """
        import traceback
        from libviri.objects import File

        try:
            success, res = File.execute(self.db, file_name_or_id,
                args, self.context, cert)
        except File.Missing:
            return (ERROR, 'File not found')
        except:
            return (ERROR, traceback.format_exc())
        else:
            return (SUCCESS if success else ERROR, res)
示例#13
0
文件: rpcserver.py 项目: timypcr/viri
    def exists(self, cert, file_id):
        """Returns True if a file with the given id exists."""
        from libviri.objects import File

        return (SUCCESS, File.exists(self.db, file_id))
示例#14
0
    def exists(self, cert, file_id):
        """Returns True if a file with the given id exists."""
        from libviri.objects import File

        return (SUCCESS, File.exists(self.db, file_id))