def checkinstalled(package): try: snapinfo = Snapd.Client().get_snap_sync(package) except Exception as e: return (2) else: return (1)
def retrieve_package_information_by_name(self, name: str) -> List[Dict]: """ Look for packages using a name provided """ snap = self.snap_client.find_sync(flags=Snapd.FindFlags(1), query=name) return self._create_array_dicts_from_array( snap[0]) # ( [ Snaps ], suggested_currency: )
def __init__(self): ProviderPlugin.__init__(self) self.items = dict() # Ensure communication with snapd daemon self.snapd_client = snapd.Client() self.snapd_client.connect_sync() self.snapd_client.get_system_information_sync() self.children = [] self.children.append(SnapdCategory())
def connect(): global client if client == None: client = Snapd.Client() client.connect_sync() auth_data = load_auth_data() if auth_data: client.set_auth_data(auth_data) else: snap_login()
def execute_action(self,action,applist=None,store=None,results=0): if store: self.store=store else: self.store=appstream.Store() self.progress=0 self.result['status']={'status':-1,'msg':''} self.result['data']='' self.snap_client=Snapd.Client() try: self.snap_client.connect_sync(None) except Exception as e: self.disabled=True #self._debug("Disabling snap %s"%e) if self.disabled==True: self._set_status(9) self.result['data']=self.store else: self._check_dirs() dataList=[] if action=='load': self.result['data']=self._load_snap_store(self.store) else: for app_info in applist: self.partial_progress=0 if action=='install': dataList.append(self._install_snap(app_info)) if action=='remove': dataList.append(self._remove_snap(app_info)) if action=='pkginfo': dataList.append(self._get_info(app_info)) self.progress+=round(self.partial_progress/len(applist),1) if self.progress>98: self.progress=98 self.result['data']=list(dataList) self.progress=100 return(self.result)
def init_snapd(self): self.snapd_client = Snapd.Client()
def snap_login(): def _ask_for_username(): # Invite user to sign up for account. try: question = subprocess.check_output(["zenity", "--question", \ "--title", "Authentication for Snappy", \ "--text", "To install snaps from the Ubuntu Store (without being root), you need an Ubuntu One account.\n\nDo you have an Ubuntu One account?", \ "--ok-label", "Continue", \ "--cancel-label", "Sign up"]).decode("ascii") except subprocess.CalledProcessError: # Zenity produces exit code 1 on cancel. # Presume cancelled subprocess.Popen(["xdg-open", "https://login.ubuntu.com/"]) # Prompt for username try: username = subprocess.check_output(["zenity", "--entry", \ "--title", "Authentication for Snappy", \ "--text", "Please enter your e-mail address for your Ubuntu One account."]).decode('ascii').replace('\n', '') return username except subprocess.CalledProcessError: subprocess.call(["zenity", "--error", \ "--title", "Authentication for Snappy", \ "--text", "No credentials were supplied. This snap cannot be installed."]) return None def _ask_for_password(): # Prompt for password try: password = subprocess.check_output(["zenity", "--password", \ "--title", "Authentication for Snappy", \ "--text", "Please enter your Ubuntu One password."]).decode('ascii').replace('\n', '') return password except subprocess.CalledProcessError: subprocess.call(["zenity", "--error", \ "--title", "Authentication for Snappy", \ "--text", "No credentials were supplied. This snap cannot be installed."]) return None def _ask_for_2FA(): # Get 2FA try: twofactorauth = subprocess.check_output(["zenity", "--entry", \ "--title", "Authentication for Snappy", \ "--text", "Please enter your 2 factor authentication code."]).decode('ascii').replace('\n', '') return twofactorauth except subprocess.CalledProcessError: subprocess.call(["zenity", "--error", \ "--title", "Authentication for Snappy", \ "--text", "No credentials were supplied. This snap cannot be installed."]) return None username = _ask_for_username() password = _ask_for_password() try: auth_data = Snapd.login_sync(username, password, None) except Exception as e: if e.domain == 'snapd-error-quark' and e.code == Snapd.Error.TWO_FACTOR_REQUIRED: otp = _ask_for_2FA() try: auth_data = Snapd.login_sync(username, password, otp) except: return None else: return None client.set_auth_data(auth_data) save_auth_data(auth_data) return True
def __init__(self, progress_publisher=None): super().__init__(progress_publisher=progress_publisher) self.snap_client = Snapd.Client().new() self._channel = "stable"
def __init__(self): self._snapd_client = Snapd.Client() self._cancellable = Gio.Cancellable()
def retrieve_package_information_by_name(self, name): snap = self.snap_client.find_sync(flags=Snapd.FindFlags(1), query=name) return self._create_dict_from_array(snap[0]) # ( [ Snaps ], suggested_currency: )
def __init__(self, progress_publisher=None): self.snap_client = Snapd.Client().new() self.channel = "stable" self.package_type = "snap" self.progress_publisher = progress_publisher
def __init__(self): self.client = Snapd.Client()