Creating binary patch files containing changes in the directory
Project description
Creating binary patch files containing changes in the directory
Simple usage :
from stateman import GetState, GetDiff, CreatePatch, ApplyPatch
import os
import shutil
patch_file="new.patch"
def write_file(filename, text):
with open(filename,'w') as f:
f.write(text)
# Clear workspace
if os.path.exists(".tmp"):
shutil.rmtree(".tmp")
if os.path.exists(".tmp2"):
shutil.rmtree(".tmp2")
# Init workspace .tmp with one subfolder
root_dir = os.path.abspath(".tmp")
target_dir = os.path.abspath(".tmp2")
os.makedirs(".tmp")
subfolder = os.path.join(root_dir,".git")
os.makedirs(subfolder)
# Create files in workspace
write_file(os.path.join(subfolder,"testfile1.txt"), "test1")
write_file(os.path.join(subfolder,"testfile2.txt"), "test2")
write_file(os.path.join(root_dir,"testfile3.txt"), "test3")
write_file(os.path.join(root_dir,"testfile4.txt"), "test4")
# Get state of workspace
state1 = GetState(root_dir, exclude = r'.git'+os.path.sep)
print(state1)
# Make a copy of workspace
shutil.copytree(root_dir, target_dir)
# Make a changes
os.remove(os.path.join(subfolder,"testfile2.txt"))
os.remove(os.path.join(root_dir,"testfile4.txt"))
write_file(os.path.join(subfolder,"testfile2.txt"), "changed")
# Get state of workspace after changes
state2 = GetState(root_dir, exclude = r'.git'+os.path.sep)
print(state2)
# Get diff between spaces
diff = GetDiff(state1, state2)
print (diff)
# Create patch file
CreatePatch(root_dir, patch_file, diff)
# Apply patch on copy of workspace, maked before changes
ApplyPatch(target_dir, patch_file, exclude = r'.git'+os.path.sep)
# Copy of workspace after apply patch identical as workspace
Source Code:
Travis CI Deploys:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
stateman-1.2.1.tar.gz
(3.4 kB
view details)
Built Distribution
File details
Details for the file stateman-1.2.1.tar.gz
.
File metadata
- Download URL: stateman-1.2.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.6.7 Linux/4.15.0-1077-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbfdc6b6accb4ed3d222932eb64f66992ac85d1f9c26c0bc6b966e6fe4a39d97 |
|
MD5 | e3fa7130f2e9e82df65e9701939d4a40 |
|
BLAKE2b-256 | 7c40c3c74fcff6292ee8272074bcac6d5195186946ee9d63f5b8c68bb3dd444c |
File details
Details for the file stateman-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: stateman-1.2.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.6.7 Linux/4.15.0-1077-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5e676ff81022081ceb1fb2866ed19134099af71e8c1be98820a3a4240359725 |
|
MD5 | b27876203f1a9b448e97262ef9ca1a6b |
|
BLAKE2b-256 | ae84b8a4c9bd717c810bb4c45cecf3db3fa7df51a6246e10793626bcc3f69079 |