Skip to content

Commit

Permalink
Reflect module restucture
Browse files Browse the repository at this point in the history
  • Loading branch information
mjiggidy committed Feb 27, 2025
1 parent 6807065 commit 1865791
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 16 additions & 7 deletions examples/hold_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@

import sys, pathlib
from binlock import BinLock
from binlock.exceptions import BinLockExistsError
from binlock.defaults import DEFAULT_LOCK_NAME

USAGE = f"Usage: {pathlib.Path(__file__).name} path_to_bin.avb [OptionalBinLockName]"

if __name__ == "__main__":

if not len(sys.argv) > 1:
print(f"Usage: {pathlib.Path(__file__).name} path_to_bin.avb", file=sys.stderr)
print(USAGE, file=sys.stderr)
sys.exit(1)

path_bin = pathlib.Path(sys.argv[1])
if not path_bin.suffix.lower() == ".avb":
print(f"Expecting a `.avb` file here, got {path_bin} instead", file=sys.stderr)
print(USAGE, file=sys.stderr)
sys.exit(2)

lock_name = sys.argv[2] if len(sys.argv) > 2 else DEFAULT_LOCK_NAME

with BinLock().hold_bin(path_bin) as lock:
input(f"Holding lock on {path_bin} as {lock.name}... (press any key)")

if BinLock().from_bin(path_bin):
print("Somehow unable to release bin")
try:
with BinLock(lock_name).hold_bin(path_bin) as lock:
input(f"Holding lock on {path_bin} as {lock.name}... (press any key)")

except BinLockExistsError as e:
print(f"Bin is already locked by {BinLock.from_bin(path_bin).name}")
sys.exit(3)

print("Lock released")
else:
print("Lock released")
6 changes: 3 additions & 3 deletions tests/test_binlock.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import pytest
import pathlib
from binlock import (
BinLock,
from binlock import BinLock
from binlock.defaults import MAX_NAME_LENGTH
from binlock.exceptions import (
BinLockNameError,
BinLockFileDecodeError,
BinLockExistsError,
BinLockOwnershipError,
)

from binlock.binlock import MAX_NAME_LENGTH

# Helper to create a dummy bin file (with a .avb extension)
def create_dummy_bin(tmp_path):
Expand Down

0 comments on commit 1865791

Please sign in to comment.