Example #1
0
	def pollDevices(self, *_):
		"""Refresh the storage dropdown list with available devices.
			
			Note: We can't use a storageMediaSelect here, because the
				device may not be usable storage media."""
		
		run(self,
			['lsblk', '--pairs', '--output=NAME,SIZE,TYPE'],
			lambda exitStatus: 
				self.uiLocalMediaFeedback.showError(
					f'Could not read storage devices.\n("lsblk" exited with code {exitStatus}.)' ),
			self.pollDevices2 )
Example #2
0
	def testNetworkStorage(self):
		self.uiNetworkStorageFeedback.showMessage(f'Working…'),
		
		#TODO: This needs to be exposed to the web app, so it needs to go through the API.
		run(self,
			['mount', '-t', 'cifs', '-o', 
				f'user={self.uiNetworkStorageUsername.text()},password={self.uiNetworkStoragePassoword.text()}', 
				f'//{self.uiNetworkStorageAddress.text()}/', '/mnt/cam' ],
			
			lambda exitStatus: 
				self.uiNetworkStorageFeedback.showError(f'Could not connect.'), #Mm, cryptic.
			
			lambda *_:
				self.uiNetworkStorageFeedback.showMessage(
					f'Network storage connected successfully!' ),
		)
Example #3
0
	def updateMountedDeviceList(self, *_):
		"""Refresh the "Mounted Devices" display.
			
			We observe externalStorage for this, since it changes
			when the mounted devices change."""
		
		run(self,
			['df', '--human-readable', 
				'--exclude=tmpfs', '--exclude=devtmpfs', 
				'--output=source,avail,used,pcent,target' ],
			
			lambda exitStatus: 
				self.uiMountedDeviceList.setText(
					f'Could not read storage devices.\n("df" exited with code {exitStatus}.)' ),
			
			self.uiMountedDeviceList.setText,
		)
Example #4
0
	def updateQRCodes(self):
		interface = self.uiNetworkInterface.currentData()
		HTTPPort = f'\n :{self.uiHTTPPort.text()}' if not self.uiHTTPPort.text() == '80' else '' #don't show default ports, they're implicit
		SSHPort = f'\n -p {self.uiSSHPort.text()}' if not self.uiSSHPort.text() == '22' else ''
		appUrl = f"http://{interface['address']}{HTTPPort}/app" 
		sshCommand = f"ssh root@{interface['address']}{SSHPort}"
		
		external_process.run(self,
			['qrencode', '-o', '-', appUrl],
			lambda err: None,
			lambda data: self.updateAppQRCode(self.uiAppUrlQRCode, data),
			binaryOutput = True,
		)
		external_process.run(self,
			['qrencode', '-o', '-', sshCommand],
			lambda err: None,
			lambda data: self.updateAppQRCode(self.uiSSHCommandQRCode, data),
			binaryOutput = True,
		)
Example #5
0
	def reloadHTTP(self):
		if not settings.value('http enabled', True):
			return
		
		self.uiHTTPStatus.showMessage(
			f"Status: Working…",
			timeout = 0 )
		
		external_process.run(self,
			['service', 'chronos-web-api', 'restart'],
			
			lambda err: (
				self.uiHTTPStatus.showError(
					f"Status: Error. See journalctl.", 
					timeout = 0 ),
				log.error(f'[4wQyPn] external process returned {err}'),
			),
			
			lambda *_:
				self.uiHTTPStatus.showMessage(
					f"Status: Running.",
					timeout = 0 )
		)
Example #6
0
	def reloadSSH(self):
		if not settings.value('ssh enabled', False):
			return
		
		self.uiSSHStatus.showMessage(
			f"Status: Working…",
			timeout = 0 )
		
		external_process.run(self,
			['service', 'ssh', 'reload'],
			
			lambda err: (
				self.uiSSHStatus.showError(
					f"Status: Error. (See journalctl -xn.)", 
					timeout = 0 ),
				log.error(f'Internal command failed with code {err}.'),
			),
			
			lambda *_:
				self.uiSSHStatus.showMessage(
					f"Status: Running.",
					timeout = 0 )
		)
Example #7
0
	def setHTTP(self, *, on=True):
		log.debug(f'setHTTP {on}')
		settings.setValue('http enabled', on)
		
		if on:
			self.uiHTTPStatus.showMessage(
				f"Status: Starting…",
				timeout = 0 )
			
			external_process.run(self,
				['systemctl', 'enable', 'chronos-web-api'],
				
				lambda err: (
					self.uiHTTPStatus.showError(
						f"Status: Error. See journalctl.", 
						timeout = 0 ),
					log.error(f'Internal command failed with code {err}.'),
				),
				
				lambda *_: external_process.run(self,
					['service', 'chronos-web-api', 'start'],
					
					lambda err: (
						self.uiHTTPStatus.showError(
							f"Status: Error. See journalctl.", 
							timeout = 0 ),
						log.error(f'Internal command failed with code {err}.'),
					),
					
					lambda *_:
						self.uiHTTPStatus.showMessage(
							f"Status: Running.",
							timeout = 0 )
				)
			)
		
		else: #off
			self.uiHTTPStatus.showMessage(
				f"Status: Stopping…",
				timeout = 0 )
			
			external_process.run(self,
				['service', 'chronos-web-api', 'stop'],
				
				lambda err: (
					self.uiHTTPStatus.showError(
						f"Status: Error. See journalctl.", 
						timeout = 0 ),
					log.error(f'[9quMdB] external process returned {err}'),
				),
				
				lambda *_: external_process.run(self,
					['systemctl', 'disable', 'chronos-web-api'],
					
					lambda err: (
						self.uiHTTPStatus.showError(
							f"Status: Error. See journalctl.", 
							timeout = 0 ),
						log.error(f'[kNIh2U] external process returned {err}'),
					),
					
					lambda *_:
						self.uiHTTPStatus.showMessage(
							f"Status: Stopped.",
							timeout = 0 )
				)
			)
Example #8
0
	def setSSH(self, *, on=True):
		log.debug(f'setSSH {on}')
		settings.setValue('ssh enabled', on)
			
		if on:
			self.uiSSHStatus.showMessage(
				f"Status: Starting…",
				timeout = 0 )
			
			external_process.run(self,
				['systemctl', 'enable', 'ssh'],
				
				lambda err: (
					self.uiSSHStatus.showError(
						f"Status: Error. See journalctl.", 
						timeout = 0 ),
					log.error(f'[wf8F10] external process returned {err}'),
				),
				
				lambda *_: external_process.run(self,
					['service', 'ssh', 'start'],
					
					lambda err: (
						self.uiSSHStatus.showError(
							f"Status: Error. See journalctl.", 
							timeout = 0 ),
						log.error(f'[iJGaZW] external process returned {err}'),
					),
					
					lambda *_:
						self.uiSSHStatus.showMessage(
							f"Status: Running.",
							timeout = 0 )
				)
			)
		
		else: #off
			self.uiSSHStatus.showMessage(
				f"Status: Stopping…",
				timeout = 0 )
			
			external_process.run(self,
				['service', 'ssh', 'stop'],
				
				lambda err: (
					self.uiSSHStatus.showError(
						f"Status: Error. See journalctl.", 
						timeout = 0 ),
					log.error(f'Internal command failed with code {err}.'),
				),
				
				lambda *_: external_process.run(self,
					['systemctl', 'disable', 'ssh'],
					
					lambda err: (
						self.uiSSHStatus.showError(
							f"Status: Error. See journalctl.", 
							timeout = 0 ),
						log.error(f'Internal command failed with code {err}.'),
					),
					
					lambda *_:
						self.uiSSHStatus.showMessage(
							f"Status: Stopped.",
							timeout = 0 )
				)
			)