• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

twisted / twisted / 1

22 Jul 2021 06:33AM UTC coverage: 80.076% (-2.3%) from 82.403%
1

push

github

web-flow
Merge branch 'trunk' into trunk

27108 of 35905 branches covered (75.5%)

1810 of 1944 new or added lines in 189 files covered. (93.11%)

119955 of 149802 relevant lines covered (80.08%)

0.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/twisted/python/shortcut.py
1
# Copyright (c) Twisted Matrix Laboratories.
2
# See LICENSE for details.
3

4

5
"""
×
6
Creation of  Windows shortcuts.
7

8
Requires win32all.
9
"""
10

NEW
11
from win32com.shell import shell  # type: ignore[import]
×
NEW
12
import pythoncom  # type: ignore[import]
×
13
import os
×
14

15

16
def open(filename):
×
17
    """
18
    Open an existing shortcut for reading.
19

20
    @return: The shortcut object
21
    @rtype: Shortcut
22
    """
23
    sc = Shortcut()
×
24
    sc.load(filename)
×
25
    return sc
×
26

27

28
class Shortcut:
×
29
    """
30
    A shortcut on Win32.
31
    """
32

33
    def __init__(
×
34
        self,
35
        path=None,
36
        arguments=None,
37
        description=None,
38
        workingdir=None,
39
        iconpath=None,
40
        iconidx=0,
41
    ):
42
        """
43
        @param path: Location of the target
44
        @param arguments: If path points to an executable, optional arguments
45
                      to pass
46
        @param description: Human-readable description of target
47
        @param workingdir: Directory from which target is launched
48
        @param iconpath: Filename that contains an icon for the shortcut
49
        @param iconidx: If iconpath is set, optional index of the icon desired
50
        """
51
        self._base = pythoncom.CoCreateInstance(
×
52
            shell.CLSID_ShellLink,
53
            None,
54
            pythoncom.CLSCTX_INPROC_SERVER,
55
            shell.IID_IShellLink,
56
        )
57
        if path is not None:
×
58
            self.SetPath(os.path.abspath(path))
×
59
        if arguments is not None:
×
60
            self.SetArguments(arguments)
×
61
        if description is not None:
×
62
            self.SetDescription(description)
×
63
        if workingdir is not None:
×
64
            self.SetWorkingDirectory(os.path.abspath(workingdir))
×
65
        if iconpath is not None:
×
66
            self.SetIconLocation(os.path.abspath(iconpath), iconidx)
×
67

68
    def load(self, filename):
×
69
        """
70
        Read a shortcut file from disk.
71
        """
72
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(
×
73
            os.path.abspath(filename)
74
        )
75

76
    def save(self, filename):
×
77
        """
78
        Write the shortcut to disk.
79

80
        The file should be named something.lnk.
81
        """
82
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(
×
83
            os.path.abspath(filename), 0
84
        )
85

86
    def __getattr__(self, name):
×
87
        return getattr(self._base, name)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc