diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index a40a899..8533669 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -11,7 +11,7 @@ jobs: runs-on: windows-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, 3.10.6] + python-version: [3.7, 3.8, 3.9, 3.10.11] steps: - uses: actions/checkout@v2 diff --git a/setup.py b/setup.py index e431612..fecbb9b 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ long_description = f.read() setup(name='pywinsandbox', - version='1.3.0', + version='1.4.0', description=u"Python Utilities for Windows Sandbox", long_description=long_description, long_description_content_type='text/markdown', diff --git a/winsandbox/config/config_genereator.py b/winsandbox/config/config_genereator.py index 341292e..1afb44d 100644 --- a/winsandbox/config/config_genereator.py +++ b/winsandbox/config/config_genereator.py @@ -16,6 +16,8 @@ def _format_folder_mappers(folder_mappers, tag, text): def generate_config_file(config): + config.folder_mappers = list(filter(lambda m: m.path().exists(), config.folder_mappers)) + document, tag, text = yattag.Doc().tagtext() with tag('Configuration'): diff --git a/winsandbox/session/online_session.py b/winsandbox/session/online_session.py index 48df4f2..201d3ab 100644 --- a/winsandbox/session/online_session.py +++ b/winsandbox/session/online_session.py @@ -73,7 +73,11 @@ def _get_logon_script(self, server_address_path): remote_python_path = sys.executable.replace(str(PythonMapper().path()), str( shared_folder_path_in_sandbox(PythonMapper().path()))) - remote_user_site_packages_path = shared_folder_path_in_sandbox(PythonUserSitePackagesMapper().path()) + user_site_path = PythonUserSitePackagesMapper().path() + if user_site_path.exists(): + remote_user_site_packages_path = shared_folder_path_in_sandbox(user_site_path) + else: + remote_user_site_packages_path = '' # Launch the target script. commands.append(r'{} {} --disable-firewall {} {}'.format( @@ -119,7 +123,7 @@ def configure_sandbox(self): self.sandbox.config.logon_script = self._get_logon_script(self.server_address_path_in_sandbox) self.sandbox.config.folder_mappers.extend(extra_folder_mappers) - def connect_to_sandbox(self, timeout=30): + def connect_to_sandbox(self, timeout=60): """ Connect to the sandbox sever. Waits for the creation of the shared server address file, and checks that it responds. diff --git a/winsandbox/target.py b/winsandbox/target.py index f0fd24d..2fdf4c5 100644 --- a/winsandbox/target.py +++ b/winsandbox/target.py @@ -16,13 +16,14 @@ def enable_python_incoming_firewall(): # Using `{sys.base_exec_prefix}\python.exe` instead of `sys.executable` to support venvs. - subprocess.run( - 'netsh advfirewall firewall add rule name=AllowPythonServer ' - 'dir=in action=allow enable=yes program="{}\\python.exe"'.format(Path(sys.base_exec_prefix).resolve()), - check=True, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL - ) + for python_executable in ['python.exe', 'python3.exe']: + subprocess.run( + 'netsh advfirewall firewall add rule name=AllowPythonServer ' + 'dir=in action=allow enable=yes program="{}\\{}"'.format(Path(sys.base_exec_prefix).resolve(), python_executable), + check=True, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL + ) def get_ip_address(): @@ -35,14 +36,17 @@ def main(): parser.add_argument("address_path", type=lambda p: Path(p)) parser.add_argument("custom_user_site_packages", - type=str) + type=str, + default='', + nargs='?') parser.add_argument("--disable-firewall", '-f', default=False, action='store_true') args = parser.parse_args() if args.disable_firewall: enable_python_incoming_firewall() - site.addsitedir(args.custom_user_site_packages) + if args.custom_user_site_packages: + site.addsitedir(args.custom_user_site_packages) import rpyc.utils.server