Ejemplo n.º 1
0
    def remove(self, app: app) -> bool:
        for i, stored in enumerate(self.applist):
            if stored.getAppId() == app.getAppId() and stored.getRepoName(
            ) == app.getRepoName():
                self.applist.pop(i)

        return True
Ejemplo n.º 2
0
    def add(self, app: app) -> bool:
        if app.getAppId().endswith(".BaseApp"):
            return False

        self.applist.append(app)
        self.count += 1
        return True
Ejemplo n.º 3
0
 def unmask(self, app: app) -> bool:
     cmd = "flatpak unmask {}".format(app.getAppId())
     result = subprocess.run(cmd,
                             shell=True,
                             universal_newlines=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     return True
Ejemplo n.º 4
0
 def isInstalled(self, app: app) -> bool:
     cmd = "flatpak list | grep -c {}".format(app.getAppId())
     result = subprocess.run(cmd,
                             shell=True,
                             universal_newlines=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     if int(result.stdout.strip()) > 0:
         return True
     else:
         return False
Ejemplo n.º 5
0
 def remove(self, app: app) -> bool:
     cmd = "flatpak remove --assumeyes --noninteractive {}".format(
         app.getAppId())
     result = subprocess.run(cmd,
                             shell=True,
                             universal_newlines=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     if result.returncode == 0:
         return True
     else:
         return False
Ejemplo n.º 6
0
    def execute(self):

        config = readconfig(self.conf)
        if config.read():
            settings = config.getSettings()
            repolist = config.getRepoList()
            applist = config.getAppList()

            repoact = repoaction()
            for repo in repolist.getAll():

                if not repoact.isInstalled(repo):
                    my.debug('Installing {} repo'.format(repo.getName()))
                    if not repoact.add(repo):
                        my.error('Failed to install {} repo'.format(
                            repo.getName()))

                # Install Applications
            for app in applist.getAll():
                action = appaction()
                permaction = permissionaction()

                if action.isInstalled(app):
                    mylog.debug('{} already installed'.format(app.getAppId()))
                else:
                    if self.dryrun:
                        mylog.info('{} to be installed'.format(app.getAppId()))
                    elif action.install(app):
                        mylog.info('{} installation successful'.format(
                            app.getAppId()))
                    else:
                        mylog.error('{} installation failed'.format(
                            app.getAppId()))

                perms = app.getPermissions()
                if perms.getCount() > 0:
                    mylog.debug('{} has overriding permissions'.format(
                        app.getAppId()))
                    for permission in perms.getAll():
                        if permaction.override(app, permission):
                            mylog.debug(" permission set")
                        else:
                            mylog.error(
                                "{} failed to set permission '{}'".format(
                                    app.getAppId(),
                                    permission.getPermission()))

                #else
                #    mylog.debug('{} has no overriding permissions'.format(app.getAppId()))
        else:
            mylog.info('failed to read configuration')
Ejemplo n.º 7
0
    def write(self):

        # Global Settings
        settingsyaml = {
            'remove_unmanaged_repos': self.settings.getRemoveUnmanagedRepos(),
            'remove_unmanaged_apps': self.settings.getRemoveUnmanagedApps()
        }

        # Set Repository
        repoyaml = []
        for repo in self.repolist.getAll():
            repodata = {
                'name': repo.getName(),
                'repo': repo.getLocation(),
                'type': repo.getType()
            }
            repoyaml.append(repodata)

            # Applications
        appyaml = []
        for app in self.applist.getAll():
            version = app.getVersion() if app.isMasked() else 'latest'
            appdata = {
                'name': app.getAppId(),
                'repo': app.getRepoName(),
                'version': version,
                'pin': app.isMasked()
            }

            # Set Application Permissions
            permlist = app.getPermissions()
            if permlist.getCount() > 0:
                perms = []
                for perm in permlist.getAll():
                    permstr = "{}={}".format(perm.getPermission(),
                                             perm.getValue())
                    perms.append(permstr)
                appdata['permissions'] = perms

            appyaml.append(appdata)

            # Create Full data structure
        data = {
            'sync': {
                'flatpak': {
                    'settings': settingsyaml,
                    'repos': repoyaml,
                    'apps': appyaml
                }
            }
        }

        # Check if path is writable
        os.path.exists(self.config)

        # Check if writable
        os.access(self.config, os.W_OK)

        # Open as writable
        try:
            with open(self.config, 'w') as f:
                json.dump(data, f, indent=4)
                #result = yaml.dump(data, f)
        except IOError as e:
            mylog.error("Failed to write configuration file")
            return False

        return True
Ejemplo n.º 8
0
 def reset(self):
     cmd = "flatpak install --assumeyes --noninteractive {} {}".format(app.getRepoName(), app.getAppId())
     return True