Skip to main content

Locks

The Locks API in Anchorpoint provides file locking functionality to prevent concurrent modifications and ensure workflow integrity. File locks are essential for collaborative workflows, especially with binary files that cannot be merged automatically.

Usage

Lock-related functions are accessed directly from the anchorpoint module and work in conjunction with Context to manage file access in projects.

import anchorpoint

ctx = anchorpoint.get_context()

# Basic lock operation
anchorpoint.lock(
ctx.workspace_id,
ctx.project_id,
[ctx.path],
description="Working on texture adjustments"
)

# Perform your work...

# Unlock when finished
anchorpoint.unlock(ctx.workspace_id, ctx.project_id, [ctx.path])

Functions

  • lock(workspace_id, project_id, targets, description=None, metadata=None) Locks one or more files or folders to prevent other users from modifying them. Locked files appear with a lock indicator in Anchorpoint and prevent conflicts during collaborative work.

    Arguments

    • workspace_id (str): Unique identifier of the workspace
    • project_id (str): Unique identifier of the project
    • targets (List[str]): List of absolute file or folder paths to lock
    • description (str, optional): Human-readable description of why files are locked
    • metadata (Dict[str, str], optional): Additional metadata associated with the lock
  • unlock(workspace_id, project_id, targets, force=False) Unlocks previously locked files or folders, allowing other users to modify them again.

    Arguments

    • workspace_id (str): Unique identifier of the workspace
    • project_id (str): Unique identifier of the project
    • targets (List[str]): List of absolute file or folder paths to unlock
    • force (bool, optional): Force unlock even if you are not the lock owner (requires appropriate permissions)
  • get_locks(workspace_id, project_id) Retrieves all current locks within a project, including lock details and ownership information.

    Arguments

    • workspace_id (str): Unique identifier of the workspace
    • project_id (str): Unique identifier of the project

    Returns (List[Lock]): List of Lock objects representing all active locks

  • evaluate_locks(workspace_id, project_id) Triggers lock evaluation and synchronization within the project. Useful for refreshing lock states and ensuring consistency.

    Arguments

    • workspace_id (str): Unique identifier of the workspace
    • project_id (str): Unique identifier of the project
  • update_locks(workspace_id, project_id, locks) Updates lock information for existing locks. Used internally for synchronization but can be called manually when needed.

    Arguments

    • workspace_id (str): Unique identifier of the workspace
    • project_id (str): Unique identifier of the project
    • locks (List[Lock]): List of Lock objects to update

LockDisabler Class

  • class LockDisabler() Context manager that temporarily disables lock evaluation during batch operations. Useful when performing multiple file operations that might trigger unnecessary lock checks.

Usage

with anchorpoint.LockDisabler():
# Perform multiple file operations without lock overhead
pass

Lock Class

The Lock class represents a file or folder lock with the following properties:

Properties

  • path (str): Absolute path to the locked file or folder.
  • owner (str): Username of the lock owner.
  • description (str): Description of why the file is locked.
  • metadata (Dict[str, str]): Additional lock metadata.
  • timestamp (datetime): When the lock was created.

Examples

Basic File Locking

import anchorpoint

ctx = anchorpoint.get_context()

# Lock the currently selected file
if ctx.path:
anchorpoint.lock(
ctx.workspace_id,
ctx.project_id,
[ctx.path],
description=f"Editing {ctx.filename}"
)
print(f"Locked: {ctx.filename}")

# Later, unlock the file
anchorpoint.unlock(ctx.workspace_id, ctx.project_id, [ctx.path])
print(f"Unlocked: {ctx.filename}")

Batch File Operations

import anchorpoint
import os

ctx = anchorpoint.get_context()

# Lock multiple files before batch processing
files_to_process = [
"/project/models/character.fbx",
"/project/models/environment.fbx",
"/project/textures/character_diffuse.png"
]

# Lock all files with descriptive message
anchorpoint.lock(
ctx.workspace_id,
ctx.project_id,
files_to_process,
description="Batch processing: Optimizing models and textures",
metadata={"batch_id": "optimization_001", "tool": "model_optimizer"}
)

try:
# Perform batch processing
for file_path in files_to_process:
print(f"Processing: {os.path.basename(file_path)}")
# Your processing logic here

finally:
# Always unlock files when done
anchorpoint.unlock(ctx.workspace_id, ctx.project_id, files_to_process)
print("Batch processing complete - all files unlocked")

Lock Management and Monitoring

import anchorpoint

ctx = anchorpoint.get_context()

def show_project_locks():
"""Display all locks in the current project"""
if not ctx.project_id:
print("Not in a project context")
return

locks = anchorpoint.get_locks(ctx.workspace_id, ctx.project_id)

if not locks:
print("No locks found in project")
return

print(f"Found {len(locks)} locks:")
for lock in locks:
print(f" 📁 {lock.path}")
print(f" Owner: {lock.owner}")
print(f" Reason: {lock.description}")
if lock.metadata:
print(f" Metadata: {lock.metadata}")
print()

def unlock_my_files():
"""Unlock all files locked by current user"""
locks = anchorpoint.get_locks(ctx.workspace_id, ctx.project_id)
my_locks = [lock.path for lock in locks if lock.owner == ctx.username]

if my_locks:
anchorpoint.unlock(ctx.workspace_id, ctx.project_id, my_locks)
print(f"Unlocked {len(my_locks)} files owned by you")
else:
print("No files locked by you")

# Show current locks
show_project_locks()

# Unlock your files
unlock_my_files()