Attributes#

These functions show how to set and read attributes on files and folders. A fully-fledged example that sets attributes on all selected files and folders can be found on GitHub.

Text Attribute#

apsync.set_attribute_text(absolute_path: str, attribute_title: str, text: str, auto_create: bool = True, update_timeline: bool = False) None#

Sets the text content of an attribute for a given file or folder. Creates the attribute if it cannot be found and auto_create is true.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

  • text (str) – The text to set

  • auto_create (bool) – Automatically create the attribute if it not exists

  • update_timeline (bool) – True if the timeline should be notified about the update

Example

>>> apsync.set_attribute_text("image.png", "status", "my super text")
apsync.get_attribute_text(absolute_path: str, attribute_title: str) Optional[str]#

Retrieves the text content of an attribute for a given file or folder.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

Returns

The attribute text, or None.

Example

>>> value = apsync.get_attribute_text("image.png", "status")

Check Attribute#

apsync.set_attribute_checked(absolute_path: str, attribute_title: str, checked: bool, auto_create: bool = True, update_timeline: bool = False) None#

Sets the checkbox content of an attribute for a given file or folder. Creates the attribute if it cannot be found and auto_create is true.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

  • checked (str) – Check or uncheck the attribute

  • auto_create (bool) – Automatically create the attribute if it not exists

  • update_timeline (bool) – True if the timeline should be notified about the update

Example

>>> apsync.set_attribute_checked("image.png", "status", true)
apsync.get_attribute_checked(absolute_path: str, attribute_title: str) bool#

Retrieves the checkbox content of an attribute for a given file or folder.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

Returns

The attribute checkbox value

Example

>>> value = apsync.get_attribute_checked("image.png", "status")

Date Attribute#

apsync.set_attribute_date(absolute_path: str, attribute_title: str, secs_since_epoch: int, auto_create: bool = True, update_timeline: bool = False) None#

Sets the date content of an attribute for a given file or folder. The date is in seconds since the epoch. Creates the attribute if it cannot be found and auto_create is true.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

  • secs_since_epoch (int) – The date to set in seconds since the epoch

  • auto_create (bool) – Automatically create the attribute if it not exists

  • update_timeline (bool) – True if the timeline should be notified about the update

Example

>>> apsync.set_attribute_date("image.png", "due date", int(time.time()))
apsync.get_attribute_date(absolute_path: str, attribute_title: str) int#

Retrieves the date content of an attribute for a given file or folder. The date is in seconds since the epoch.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

Returns

The attribute date value

Example

>>> value = apsync.get_attribute_date("image.png", "due date")

Rating Attribute#

apsync.set_attribute_rating(absolute_path: str, attribute_title: str, rating: int, auto_create: bool = True, update_timeline: bool = False) None#

Sets the rating content of an attribute for a given file or folder. Creates the attribute if it cannot be found and auto_create is true.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

  • rating (int) – The rating to set

  • auto_create (bool) – Automatically create the attribute if it not exists

  • update_timeline (bool) – True if the timeline should be notified about the update

Returns

The attribute rating, or None.

Example

>>> apsync.set_attribute_rating("image.png", "rating", 3)
apsync.get_attribute_rating(absolute_path: str, attribute_title: str) int#

Retrieves the rating content of an attribute for a given file or folder.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

Returns

The attribute rating.

Example

>>> value = apsync.get_attribute_rating("image.png", "rating")

Tag Attributes#

apsync.set_attribute_tag()#

Sets the tag of an attribute for a given file or folder. Creates the attribute if it cannot be found and auto_create is true.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

  • tag_name (str) – The name of the tag to set - will create a new tag if unknown

  • type (apsync.AttributeType) – The type of attribute

  • auto_create (bool) – Automatically create the attribute if it not exists

  • tag_color (apsync.TagColor) – The color of the created tag - or None to choose a random color

  • update_timeline (bool) – True if the timeline should be notified about the update

Example

>>> apsync.set_attribute_tag("image.png", "status", "Work in Progress")
apsync.get_attribute_tag(absolute_path: str, attribute_title: str) Optional[apsync.AttributeFieldTag]#

Retrieves the tag content of an attribute for a given file or folder.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

Returns

The attribute tag, or None.

Example

>>> tag = apsync.get_attribute_tag("image.png", "status")
>>> print(tag.name)
apsync.set_attribute_tags()#

Sets the link content of an attribute for a given file or folder. Overwrites existing tags of the attribute. Creates the attribute if it cannot be found and auto_create is true.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

  • tag_names (list) – The tags to set, identified by name

  • type (apsync.AttributeType) – The type of the attribute to create. Must be either apsync.AttributeType.multiple_choice_tag or apsync.AttributeType.single_choice_tag

  • auto_create (bool) – Automatically create the attribute if it not exists

  • update_timeline (bool) – True if the timeline should be notified about the update

Example

>>> apsync.set_attribute_tags("image.png", "clients", ["anchorpoint", "john doe"])
apsync.get_attribute_tags(absolute_path: str, attribute_title: str) List[apsync.AttributeFieldTag]#

Retrieves the list of assigned tags of a multiple or single choice tag.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

Example

>>> tags = apsync.get_attribute_tags("image.png", "clients")
apsync.add_attribute_tag()#

Adds a tag identified by name to an attribute. If not tags are assigned, this function is equivalent to set_attribute_tag(). Creates the attribute if it cannot be found and auto_create is true.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

  • tag_name (str) – The tag to add, identified by name

  • type (apsync.AttributeType) – The type of the attribute to create. Must be either apsync.AttributeType.multiple_choice_tag or apsync.AttributeType.single_choice_tag

  • auto_create (bool) – Automatically create the attribute if it not exists

  • update_timeline (bool) – True if the timeline should be notified about the update

Example

>>> apsync.add_attribute_tags("image.png", "clients", ["anchorpoint", "john doe"])
apsync.add_attribute_tags()#

Adds a list of tags identified by name to an attribute. If not tags are assigned, this function is equivalent to set_attribute_tags(). Creates the attribute if it cannot be found and auto_create is true.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

  • tag_names (list) – The tags to add, identified by name

  • type (apsync.AttributeType) – The type of the attribute to create. Must be either apsync.AttributeType.multiple_choice_tag or apsync.AttributeType.single_choice_tag

  • auto_create (bool) – Automatically create the attribute if it not exists

  • update_timeline (bool) – True if the timeline should be notified about the update

Example

>>> apsync.add_attribute_tags("image.png", "clients", ["anchorpoint", "john doe"])
apsync.remove_attribute_tag()#

Removes a tag identified by name.

Parameters
  • absolute_path (str) – Path to the file or folder

  • attribute_title (str) – Title of the attribute

  • tag_name (str) – The tag to add, identified by name

  • type (apsync.AttributeType) – The type of the attribute to create. Must be either apsync.AttributeType.multiple_choice_tag or apsync.AttributeType.single_choice_tag

Example

>>> apsync.remove_attribute_tag("image.png", "clients", "anchorpoint")
class apsync.AttributeFieldTag(name: str)#

The AttributeFieldTag class represents a tag for a single or multiple choice tag.

id#

The unique id of the attribute

Type

str

name#

The name of the attribute

Type

str

color#

The color of the tag

Type

apsync.TagColor

Example

>>> apsync.AttributeFieldTag("Work in Progress", apsync.TagColor.yellow)
class apsync.TagColor#
class apsync.TagColor(color: str)

The TagColor class represents the color of a single or multiple choice tag. It can be initialized with a string value but it is recommended to use the provided properties.

red#

A red TagColor

Type

TagColor

orange#

An orange TagColor

Type

TagColor

yellow#

A yellow TagColor

Type

TagColor

green#

A green TagColor

Type

TagColor

turk#

A turk TagColor

Type

TagColor

blue#

A blue TagColor

Type

TagColor

purple#

A purple TagColor

Type

TagColor

grey#

A grey TagColor

Type

TagColor

Example

>>> red = apsync.TagColor.red
class apsync.AttributeType(type: str)#

The AttributeType class is used to identify the type of an attribute.

single_choice_tag#

Represents a single choice tag attribute

Type

apsync.AttributeType

multiple_choice_tag#

Represents a multiple choice tag attribute

Type

apsync.AttributeType

text#

Represents a rext

Type

apsync.AttributeType

rating#

Represents a rating

Type

apsync.AttributeType

Represents a hyperlink

Type

apsync.AttributeType

date#

Represents a date

Type

apsync.AttributeType

checkbox#

Represents a checkbox

Type

apsync.AttributeType

timestamp#

Represents a timestamp / time tracking attribute

Type

apsync.AttributeType

Example

>>> type = apsync.AttributeType.rating

Copy and Rename#

When copying or renaming files and folders in Anchorpoint, metadata such as attributes are adjusted on the server. Unfortunately, this information is lost when doing rename and copy operations through the OS. Instead, use the following utility functions:

apsync.copy_from_template(source: str, target: str, variables: Dict[str, str] = {}, skip_root: bool = True) str#

Copies the source (template) folder to the target path and adjusts the metadata (e.g. attributes). Pass a python dictionary of variables that are applied to the folder and all the content of the folder. Raises an exeception when the target folder already exists, use os.remove to delete a folder.

Parameters
  • source (str) – The source path

  • target (str) – The target path

  • variables (dict) – The variables that are resolved, see example

  • skip_root (bool) – If true, the root folder of source is skipped

Returns

The newly created target folder

Example

>>> variables = {
>>>     "[project]": "Commercial",
>>>     "[client]": "Anchorpoint"
>>> }
>>>
>>> apsync.copy_from_template("C:/Templates/[client]_[project]", "C:/Projects/[client]_[project]", variables)
"C:/Projects/Anchorpoint_Commercial"
apsync.copy_file_from_template(source: str, target: str, variables: Dict[str, str] = {}) str#

Copies the source (template) folder to the target path and copies the metadata for the files (e.g. reviews). Pass a python dictionary of variables that are applied to the content of the folder. Raises an exeception when the target folder already exists, use os.remove to delete a folder.

Parameters
  • source (str) – The source path

  • target (str) – The target path

  • variables (dict) – The variables that are resolved, see example

Returns

The newly created target folder

Example

>>> variables = {
>>>     "[project]": "Commercial",
>>>     "[client]": "Anchorpoint"
>>> }
>>>
>>> apsync.copy_file_from_template("C:/Templates/[client]_[project]", "C:/Projects/[client]_[project]", variables)
"C:/Projects/Anchorpoint_Commercial"
apsync.copy_file(source: str, target: str, overwrite: bool = False) None#

Copies the file from source to target including all metadata (e.g. reviews). Raises an exeception when overwrite is False and target already exists.

Parameters
  • source (str) – The source file

  • target (str) – The target file

  • overwrite (bool) – Overwrite the target file

Example

>>> apsync.copy_file(source, target, True)
apsync.copy_folder(source: str, target: str, overwrite: bool = False) None#

Copies the entire content from source_folder to the target_folder, including all metadata (e.g. attributes). Raises an exeception when overwrite is False and there is conflicts in the target_folder

Parameters
  • source_folder (str) – The source folder

  • target_folder (str) – The target folder

  • overwrite (bool) – Overwrite target_folder

Example

>>> apsync.copy_folder(source, target, True)
apsync.rename_file(source: str, target: str) None#

Renames the source file to the target name and adjusts the metadata (e.g. attributes). Raises an exeception when the target file already exists, use os.remove to delete a file.

Parameters
  • source (str) – The source file

  • target (str) – The target file

Example

>>> apsync.rename_file(source, target)
apsync.rename_folder(source: str, target: str) None#

Renames the source folder to the target name and adjusts the metadata (e.g. attributes). Raises an exeception when the target folder already exists, use os.remove to delete a folder.

Parameters
  • source (str) – The source file

  • target (str) – The target file

Example

>>> apsync.rename_folder(source, target)
apsync.resolve_variables(text: str, variables: Dict[str, str]) str#

Takes an input text, e.g. “C:/Projects/[client]_[project]” and converts it to a resolved text, e.g. “C:/Projects/anchorpoint_commercial”. Pass a python dictionary of variables where the values are the resolved variables (see example)

Parameters
  • text (str) – The source text

  • variables (dict) – The variables that are resolved, see example

Returns

The text with resolved variables

Example

>>> variables = {
>>>     "[project]": "Commercial",
>>>     "[client]": "Anchorpoint"
>>> }
>>>
>>> apsync.resolve_variables("C:/Projects/[client]_[project]", "C:/Projects/[client]_[project]", variables)
"C:/Projects/Anchorpoint_Commercial"