[App Sharing] 可替代 jetbrains-toolbox 的命令行工具
Tofloor
poster avatar
xiao80
deepin
2022-11-25 03:06
Author

一个简单的 toolbox 动不动就占用几百M 的资源。
以下脚本可取代 toolbox ,进行安装,更新和卸载,多版本共存。

 Path:
        return install_path.with_name(install_path.name + '.plugins')

    def _install_vmoptions(self, product, install_path: Path):
        vmoptions_path = install_path.with_name(install_path.name + '.vmoptions')
        plugin_path = App._plugin_path(install_path)
        vmoptions_path.write_text(os.linesep.join([
            f'-Didea.plugins.path={plugin_path}',
        ] + config['vmoptions']))


    @staticmethod
    def _find_release_by_build(build, releases):
        if build in releases: return releases.get(build)
        return next((r for r in releases.values() if r['version'] == build), None)

    def run_with_app(self, app: str, op: str, build: str):
        op = op or 'list'
        match op:
            case 'install':
                self.install(app, build)
            case 'list':
                self.list_installed_products(app)
            case 'show':
                self.show_product(app)
            case 'remove':
                self.remove(app, build)

    def run(self, op):
        op = op or 'list'
        match op:
            case 'show':
                self.show_products()
            case 'list':
                self.list_installed_products()


@pidfile("jbr-cli")
@click.command()
@click.argument('产品代码', required=False)
@click.option('-I', 'op', help='安装或升级', flag_value='install')
@click.option('-L', 'op', help='列出已安装产品,默认选项', flag_value='list')
@click.option('-S', 'op', help='列出所有产品', flag_value='show')
@click.option('-R', 'op', help='卸载', flag_value='remove')
@click.option('-b', '--build', help='版本号')
@click.help_option('-h', '--help')
def run(产品代码: str, op: str, build: str):
    cmd = App()
    if 产品代码: return cmd.run_with_app(产品代码.upper(), op, build)
    cmd.run(op)


if __name__ == '__main__':
    try:
        run()
    except PidFileAlreadyLockedError:
        sys.exit('another instance is already running, abort')
Reply Favorite View the author
All Replies
xiao80
deepin
2022-11-25 03:13
#1

Screenshot at 2022-11-24 18:41:25.png
Screenshot at 2022-11-24 18:40:45.png
Screenshot at 2022-11-24 18:40:23.png

Screenshot at 2022-11-24 18:39:48.png

Reply View the author