コード例 #1
0
def pluginToBlock(plugin, import_block = True):
    try:
        plugin = sanitize(plugin)

        directory = pluginapi.get_pluginapi().get_folder(plugin)
        data_directory = pluginapi.get_pluginapi().get_data_folder(plugin)
        zipfile = pluginapi.get_pluginapi().get_data_folder(plugin_name) + 'plugin.zip'

        if os.path.exists(directory) and not os.path.isfile(directory):
            if os.path.exists(data_directory) and not os.path.isfile(data_directory):
                shutil.rmtree(data_directory)
            if os.path.exists(zipfile) and os.path.isfile(zipfile):
                os.remove(zipfile)
            if os.path.exists(directory + '__pycache__') and not os.path.isfile(directory + '__pycache__'):
                shutil.rmtree(directory + '__pycache__')

            shutil.make_archive(zipfile[:-4], 'zip', directory)
            data = ''
            with open(zipfile, 'rb') as file:
                data = base64.b64encode(file.read())

            author = getpass.getuser()
            description = 'Default plugin description'
            info = {"name" : plugin}
            try:
                if os.path.exists(directory + 'info.json'):
                    info = ''
                    with open(directory + 'info.json').read() as file:
                        info = json.loads(file.read())

                    if 'author' in info:
                        author = info['author']
                    if 'description' in info:
                        description = info['description']
            except:
                pass

            metadata = {'author' : author, 'date' : str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')), 'name' : plugin, 'info' : info, 'compiled-by' : plugin_name, 'content' : data.decode('utf-8'), 'description' : description}

            block = Block(core = pluginapi.get_core())

            block.setType('plugin')
            block.setContent(json.dumps(metadata))

            hash = block.save(True)
            # hash = pluginapi.get_core().insertBlock(, header = 'plugin', sign = True)

            if import_block:
                pluginapi.get_utils().importNewBlocks()

            return hash
        else:
            logger.error('Plugin %s does not exist.' % plugin)
    except Exception as e:
        logger.error('Failed to convert plugin to block.', error = e, timestamp = False)

    return False
コード例 #2
0
def createRepository(plugins):
    contents = {'plugins' : plugins, 'author' : getpass.getuser(), 'compiled-by' : plugin_name}

    block = Block(core = pluginapi.get_core())

    block.setType('repository')
    block.setContent(json.dumps(contents))

    return block.save(True)
コード例 #3
0
ファイル: main.py プロジェクト: anharismail/onionr
def send():
    global message
    block = Block()
    block.setType('txt')
    block.setContent(message)
    logger.debug('Sent message in block %s.' % block.save(sign=True))