def copyFolderWithRoot(update_app_path: str, original_app: AppToUpdate): """ In case we don't have permission, we will start an external script and ask for an executing permission """ if sys_utils.isMac() or sys_utils.isLinux(): fd, installer = tempfile.mkstemp(suffix='.sh') pyqt_utils.defrostAndSaveInto(resources_utils.getResource('installers/posix/installer.sh'), installer) else: fd, installer = tempfile.mkstemp(suffix='.bat') pyqt_utils.defrostAndSaveInto(resources_utils.getResource('installers/windows/installer.bat'), installer) os.close(fd) os.chmod(installer, 0o755) # make executable command = [installer, update_app_path, original_app.folder] logger.info("Calling command %s" % ' '.join(command)) try: res_code = permission_utils.runAsAdmin(command) if res_code == 0: return else: logger.error("Exception occurred, exit code: %d" % res_code) except OSError as e: logger.error("Exception occurred, rolling back to the earlier backed up version.\n Exception: %s", e) finally: os.unlink(installer) raise InstallationFailedException()
def __init__(self): super(Home, self).__init__() self.ui = HomeUi() self.ui.resize(global_preference_service.getHomeWindowSize()) self.ui.setMinimumSize( global_preference_service.getMinimumHomeWindowSize()) self.ui.add_app.clicked.connect(self.addAppClicked) data_transporter_service.listen(CONTAINER_CHANNEL, self.addAppFromContainer) data_transporter_service.listen(ADD_APP_CHANNEL, self.addAppClicked) self.apps: Dict[int, AppWidgetUi] = {} self.groups: Dict[int, GroupWidgetUi] = {} self.ui.workspaces.on_option_selected.connect(self.onWorkspaceChanged) self.ui.resizeEvent = self.resizeEvent self.ui.search_app.textChanged.connect(self.search) self.ui.custom_menu.clicked.connect(self.onMenuClicked) # Create daemon to listen to docker events self.daemon = boatswain_daemon.BoatswainDaemon(self.ui) if not sys_utils.isMac(): self.ui.menu_bar.hide() if not docker_service.isDockerRunning(): connection = ConnectionManagement() connection.conf_updated.connect(self.initialise) connection.show() else: self.initialise()
def getExternalResource(file): """ This function will return the path to file in system resource folder after released. Depending on OS, For MacOS, the resource folder should be Boatswain.app/Contents/Resources For Window and Linux, resource folder should be the installed dir in debug mode, this will return the file in /resources folder @rtype: resource file name """ if not utils.isFrost(): return os.path.join(os.path.dirname(current_dir), "resources", file) original_app = AppToUpdate() if sys_utils.isMac(): return os.path.join(original_app.folder, 'Contents', 'Resources', file) return os.path.join(original_app.folder, file)
def runAsAdmin(argv): commands = [] if sys_utils.isMac(): # For MacOS, we will use osascript for asking privileges permission commands.append([ "osascript", "-e", "do shell script " + quoteAppleScript(quoteShell(argv)) + " with administrator privileges" ]) elif sys_utils.isLinux(): # For Linux, there are many different distro, so, we will try each of them # If all are failed, the fall back to sudo if os.environ.get("DISPLAY"): commands.append(["pkexec"] + argv) commands.append(["gksudo"] + argv) commands.append(["kdesudo"] + argv) commands.append(["sudo"] + argv) elif sys_utils.isWin(): # For window machine, we expect to have the script to ask for permission inside the .bat file already commands.append(argv) else: raise NotImplementedError('Unable to recognise platform %s' % sys.platform) for command in commands: try: if sys_utils.isWin(): return subprocess.call(command, stdin=None, stdout=None, stderr=None, shell=False, creationflags=CREATE_NO_WINDOW) else: return subprocess.call(command, stdin=None, stdout=None, stderr=None, shell=False) except OSError as e: if e.errno != errno.ENOENT or command[0] == "sudo": raise e
def fromJson(object_json): version = object_json['tag_name'] release = Release(version) release.changelog = object_json['body'] assets = object_json["assets"] if sys_utils.isMac(): # For mac, always x64 plf = 'macOS' elif sys_utils.isWin(): # For windows, depending on the architecture x32/x64. But we always looking for the portable version of it plf = 'win-%s-portable' % sys_utils.getArchitecture() else: plf = 'linux-%s' % sys_utils.getArchitecture() for asset in assets: download_info = asset if plf in download_info['name']: release.download_url = download_info["browser_download_url"] release.download_size = download_info["size"] return release
def startTerminalWithCommand(command): if sys_utils.isMac(): term = resources_utils.getExternalResource('run_with_mac_terminal.sh') if os.path.exists("/Applications/iTerm.app"): term = resources_utils.getExternalResource('run_with_iterm.sh') os.system('chmod u+x ' + term) os.system("%s \"%s\" &" % (term, command)) elif sys_utils.isWin(): os.system("start cmd /c %s" % command) else: default_linux_term = 'xterm' if os.path.exists('/etc/debian_version'): default_linux_term = 'x-terminal-emulator' elif os.path.exists('/usr/bin/xfce4-terminal'): default_linux_term = 'xfce4-terminal' elif os.environ['DESKTOP_SESSION'] == 'gnome': default_linux_term = 'gnome-terminal' elif os.environ['DESKTOP_SESSION'] == 'kde-plasma': default_linux_term = 'konsole' elif 'COLORTERM' in os.environ: default_linux_term = os.environ['COLORTERM'] elif 'TERM' in os.environ: default_linux_term = os.environ['TERM'] os.system("%s -e %s &" % (default_linux_term, command))
def applyFontRatio(point): if sys_utils.isMac(): return point return round(point * 0.8)
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Boatswain. If not, see <https://www.gnu.org/licenses/>. # # import os from PyQt5.QtGui import QGuiApplication from PyQt5.QtWidgets import QApplication from boatswain_updater.utils import sys_utils from boatswain import resources_utils ref_dpi = 72 if sys_utils.isMac() else 96 def getRefHeight(): return rt(900) def getPrimaryScreen(): return QGuiApplication.primaryScreen() def getScreenWidth(): rect = getPrimaryScreen().geometry() return rect.width()
def applyFontRatio(point): if external_font_ratio: return point * external_font_ratio if sys_utils.isMac(): return point return round(point * 0.8)