Пример #1
0
    def _install_desktop_entry(self, tp):
        # Handle the special placeholders in the specified command.  For a
        # filebrowser request, we simply used the passed filebrowser.  But
        # for a webbrowser request, we invoke the Python standard lib's
        # webbrowser script so we can force the url(s) to open in new tabs.
        spec = self.shortcut.copy()
        spec['tp'] = tp

        path = self.path
        if tp == 'gnome':
            filebrowser = 'gnome-open'
            path += '.desktop'
        elif tp == 'kde':
            filebrowser = 'kfmclient openURL'
            path += 'KDE.desktop'

        cmd = self.cmd
        if cmd[0] == '{{FILEBROWSER}}':
            cmd[0] = filebrowser
        elif cmd[0] == '{{WEBBROWSER}}':
            import webbrowser
            executable = get_executable(self.prefix)
            cmd[0:1] = [executable, webbrowser.__file__, '-t']

        spec['cmd'] = cmd
        spec['path'] = path

        # create the shortcuts
        make_desktop_entry(spec)
Пример #2
0
    def test_simple(self):
        # Given
        with mkdtemp() as prefix:
            if sys.platform == "win32":
                # python.exe is in scripts because we use virtualenv
                r_executable = os.path.join(prefix, "Scripts", "python.exe")
            else:
                r_executable = os.path.join(prefix, "bin", "python")

            create_venv(prefix)

            # When
            executable = get_executable(prefix)

        # Then
        self.assertEqual(executable, r_executable)
Пример #3
0
    def test_simple(self):
        # Given
        with mkdtemp() as prefix:
            if sys.platform == "win32":
                # python.exe is in scripts because we use virtualenv
                r_executable = os.path.join(prefix, "Scripts", "python.exe")
            else:
                r_executable = os.path.join(prefix, "bin", "python")

            create_venv(prefix)

            # When
            executable = get_executable(prefix)

        # Then
        self.assertEqual(executable, r_executable)
Пример #4
0
    def create(self, remove=False):
        # Separate the arguments to the invoked command from the command
        # itself.
        cmd = self.cmd[0]
        args = self.cmd[1:]
        executable = get_executable(self.prefix)

        # Handle the special '{{FILEBROWSER}}' command by using webbrowser
        # since using just the path name pops up a dialog asking for which
        # application to use.  Using 'explorer.exe' picks up
        # c:/windows/system32/explorer.exe which does not work.  Webbrowser
        # does the right thing.
        if cmd == '{{FILEBROWSER}}':
            cmd = executable
            args = ['-m', 'webbrowser'] + args

        # Otherwise, handle the special '{{WEBBROWSER}}' command by
        # invoking the Python standard lib's 'webbrowser' script.  This
        # allows us to specify that the url(s) should be opened in new
        # tabs.
        #
        # If this doesn't work, see the following website for details of
        # the special URL shortcut file format.  While split across two
        # lines it is one URL:
        #   http://delphi.about.com/gi/dynamic/offsite.htm?site= \
        #        http://www.cyanwerks.com/file-format-url.html
        elif cmd == '{{WEBBROWSER}}':
            cmd = executable
            args = ['-m', 'webbrowser', '-t'] + args

        # The API for the call to 'wininst.create_shortcut' has 3 required
        # arguments:-
        #
        # path, description and filename
        #
        # and 4 optional arguments:-
        #
        # args, working_dir, icon_path and icon_index
        #
        # We always pass the args argument, but we only pass the working
        # directory and the icon path if given, and we never currently pass the
        # icon index.
        working_dir = quoted(self.shortcut.get('working_dir', ''))
        icon        = self.shortcut.get('icon')
        if working_dir and icon:
            shortcut_args = [working_dir, icon]

        elif working_dir and not icon:
            shortcut_args = [working_dir]

        elif not working_dir and icon:
            shortcut_args = ['', icon]

        else:
            shortcut_args = []

        # Menu link
        dst_dirs = [self.menu.path]

        # Desktop link
        if self.shortcut.get('desktop') and addtodesktop:
            dst_dirs.append(desktop_dir)

        # Quicklaunch link
        if self.shortcut.get('quicklaunch') and addtolauncher:
            dst_dirs.append(quicklaunch_dir)

        for dst_dir in dst_dirs:
            dst = join(dst_dir, self.shortcut['name'] + '.lnk')
            if remove:
                rm_rf(dst)
            else:
                wininst.create_shortcut(
                    quoted(cmd),
                    self.shortcut['comment'],
                    dst,
                    ' '.join(quoted(arg) for arg in args),
                    *shortcut_args)
Пример #5
0
    def create(self, remove=False):
        # Separate the arguments to the invoked command from the command
        # itself.
        cmd = self.cmd[0]
        args = self.cmd[1:]
        executable = get_executable(self.prefix)

        # Handle the special '{{FILEBROWSER}}' command by using webbrowser
        # since using just the path name pops up a dialog asking for which
        # application to use.  Using 'explorer.exe' picks up
        # c:/windows/system32/explorer.exe which does not work.  Webbrowser
        # does the right thing.
        if cmd == '{{FILEBROWSER}}':
            cmd = executable
            args = ['-m', 'webbrowser'] + args

        # Otherwise, handle the special '{{WEBBROWSER}}' command by
        # invoking the Python standard lib's 'webbrowser' script.  This
        # allows us to specify that the url(s) should be opened in new
        # tabs.
        #
        # If this doesn't work, see the following website for details of
        # the special URL shortcut file format.  While split across two
        # lines it is one URL:
        #   http://delphi.about.com/gi/dynamic/offsite.htm?site= \
        #        http://www.cyanwerks.com/file-format-url.html
        elif cmd == '{{WEBBROWSER}}':
            cmd = executable
            args = ['-m', 'webbrowser', '-t'] + args

        # The API for the call to 'wininst.create_shortcut' has 3 required
        # arguments:-
        #
        # path, description and filename
        #
        # and 4 optional arguments:-
        #
        # args, working_dir, icon_path and icon_index
        #
        # We always pass the args argument, but we only pass the working
        # directory and the icon path if given, and we never currently pass the
        # icon index.
        working_dir = quoted(self.shortcut.get('working_dir', ''))
        icon = self.shortcut.get('icon')
        if working_dir and icon:
            shortcut_args = [working_dir, icon]

        elif working_dir and not icon:
            shortcut_args = [working_dir]

        elif not working_dir and icon:
            shortcut_args = ['', icon]

        else:
            shortcut_args = []

        # Menu link
        dst_dirs = [self.menu.path]

        # Desktop link
        if self.shortcut.get('desktop') and addtodesktop:
            dst_dirs.append(desktop_dir)

        # Quicklaunch link
        if self.shortcut.get('quicklaunch') and addtolauncher:
            dst_dirs.append(quicklaunch_dir)

        for dst_dir in dst_dirs:
            dst = join(dst_dir, self.shortcut['name'] + '.lnk')
            if remove:
                rm_rf(dst)
            else:
                wininst.create_shortcut(quoted(cmd), self.shortcut['comment'],
                                        dst,
                                        ' '.join(quoted(arg) for arg in args),
                                        *shortcut_args)