Magics to interact with the underlying OS (shell-type functionality).
| 30 | |
| 31 | @magics_class |
| 32 | class OSMagics(Magics): |
| 33 | """Magics to interact with the underlying OS (shell-type functionality). |
| 34 | """ |
| 35 | |
| 36 | cd_force_quiet = Bool(False, |
| 37 | help="Force %cd magic to be quiet even if -q is not passed." |
| 38 | ).tag(config=True) |
| 39 | |
| 40 | def __init__(self, shell=None, **kwargs): |
| 41 | |
| 42 | # Now define isexec in a cross platform manner. |
| 43 | self.is_posix = False |
| 44 | self.execre = None |
| 45 | if os.name == 'posix': |
| 46 | self.is_posix = True |
| 47 | else: |
| 48 | try: |
| 49 | winext = os.environ['pathext'].replace(';','|').replace('.','') |
| 50 | except KeyError: |
| 51 | winext = 'exe|com|bat|py' |
| 52 | try: |
| 53 | self.execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE) |
| 54 | except re.error: |
| 55 | warn("Seems like your pathext environmental " |
| 56 | "variable is malformed. Please check it to " |
| 57 | "enable a proper handle of file extensions " |
| 58 | "managed for your system") |
| 59 | winext = 'exe|com|bat|py' |
| 60 | self.execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE) |
| 61 | |
| 62 | # call up the chain |
| 63 | super().__init__(shell=shell, **kwargs) |
| 64 | |
| 65 | |
| 66 | @skip_doctest |
| 67 | def _isexec_POSIX(self, file): |
| 68 | """ |
| 69 | Test for executable on a POSIX system |
| 70 | """ |
| 71 | if os.access(file.path, os.X_OK): |
| 72 | # will fail on maxOS if access is not X_OK |
| 73 | return file.is_file() |
| 74 | return False |
| 75 | |
| 76 | |
| 77 | |
| 78 | @skip_doctest |
| 79 | def _isexec_WIN(self, file): |
| 80 | """ |
| 81 | Test for executable file on non POSIX system |
| 82 | """ |
| 83 | return file.is_file() and self.execre.match(file.name) is not None |
| 84 | |
| 85 | @skip_doctest |
| 86 | def isexec(self, file): |
| 87 | """ |
| 88 | Test for executable file on non POSIX system |
| 89 | """ |
nothing calls this directly
no test coverage detected