Accessing Windows from Linux
Retrieve a file (from Windows to Linux)
import pyndows
path_to_retrieved_file = ""
with pyndows.connect(...) as machine:
pyndows.get(machine, "shared_folder_name", "/folder/requested_file_name", path_to_retrieved_file)
Retrieve a file description (from Windows to Linux)
import pyndows
with pyndows.connect(...) as machine:
description = pyndows.get_file_desc(machine, "shared_folder_name", "/folder/requested_file_name")
Move a file (from Linux to Windows)
import pyndows
file_to_move_path = ""
with pyndows.connect(...) as machine:
pyndows.move(machine, "shared_folder_name", "/folder/destination_file_name", file_to_move_path)
Note that folders will be created if not existing.
You can also provide a custom suffix for the temporary file (.tmp is used by default) via the temp_file_suffix parameter.
Rename a file
import pyndows
with pyndows.connect(...) as machine:
pyndows.rename(machine, "shared_folder_name", "/folder/previous_file_name", "/folder/new_file_name")
Ensure connectivity
import pyndows
with pyndows.connect(...) as machine:
details = pyndows.check("connection identifier", machine)
Testing
You can mock remote connections by using samba_mock pytest fixture.
2 convenience methods are available:
samba_mock.path(share_folder_name, file_or_folder_path)returns apathlib.Pathinstance that you can use as a replacement for the file on the remote connection.- Use
write_*()to set the content of a file. - Use
read_*()to check the content of a file.
- Use
samba_mock.add_callback(method_name, callback)provides the ability to override the mock default behavior and can be used to send custom exceptions.
Below are a few example of what can be done:
Simulate a file that can be retrieved
from pyndows.testing import samba_mock, SMBConnectionMock
def test_file_retrieval(samba_mock: SMBConnectionMock):
samba_mock.path("shared_folder_name", "/folder/file_to_retrieve").write_text("File content of path to a file")
# TODO Execute code relying on this file
Ensure the content of a file that was moved or renamed
from pyndows.testing import samba_mock, SMBConnectionMock
def test_file_retrieval(samba_mock: SMBConnectionMock):
# TODO Execute code writing this file
file_content = samba_mock.path("shared_folder_name", "/folder/file_that_was_stored").read_text()
Simulate echo failure
from smb.smb_structs import OperationFailure
from pyndows.testing import samba_mock, SMBConnectionMock
def test_file_retrieval(samba_mock: SMBConnectionMock):
def raise_exception(*args):
raise OperationFailure("Mock for echo failure.", [])
samba_mock.add_callback("echo", raise_exception)
# TODO Execute code calling echo
How to install
- python 3.6+ must be installed
- Use pip to install module:
python -m pip install pyndows
Metadata
Release files for pyndows 4.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyndows-4.2.1.tar.gz | 7.2 kB | Without provenance | Details for pyndows-4.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyndows-4.2.1-py3-none-any.whl | Python 3 | none | any | Details for pyndows-4.2.1-py3-none-any.whl |
Total release size: 16.1 kB
Release files / pyndows-4.2.1.tar.gz
| Download URL | pyndows-4.2.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ba2e276f5f57438958bee672eb239e7a1839407d28987de108be1b5f1942883
|
|
BLAKE2b-256 checksum How to use checksums |
753a77a9bb1cd23fd87859d7bf1da4ca47c43e58c0219f7b1ece77e5a0c62d12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1
|
Release files / pyndows-4.2.1-py3-none-any.whl
| Download URL | pyndows-4.2.1-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a072f5d5e4d9c2dc9ba4a9ebccd4d927c8c62b306ac3bdf330c5c74cd02df025
|
|
BLAKE2b-256 checksum How to use checksums |
4a4df56857257aab8b9b6c8cf8a8676d5921f42cd0d7ca0af812f4163a2bfb21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1
|
Security for pyndows 4.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.