Project libraries #
You can interact with the Library of each project through the API.
Getting the DSSLibrary object #
You must first retrieve the
DSSLibrary
through the
get_library()
method
project = client.get_project("MYPROJECT")
library = project.get_library()
Retrieving the content of a file #
library_file = library.get_file("/file.txt")
print("Content: %s" % library_file.read()))
# Alternate ways to retrieve a file handle
library_file = library.get_file("/python/some_code.py")
library_file = library.get_folder("/python").get_file("/some_code.py")
Getting the list of all the library items #
def print_library_items(item):
print(item.path)
if "list" in dir(item):
for child in item.list():
print_library_items(child)
for item in lib.list():
print_library_items(item)
Add a new folder in the library #
library.add_folder("/new_folder")
library.add_folder("/python/new_sub_folder")
library.get_folder("/python").add_folder("another_sub_folder")
Add a new file in the library #
# create a new file in a folder
file = open("/path/to/local/file")
library.put_file("/new_folder/file.txt", file)
Rename a file or a folder in the library #
# rename a file in the library
library.get_file("/folder/file.txt").rename("renamed_file.txt")
# rename a folder in the library
library.get_folder("/folder").rename("renamed_folder")
Move a file or a folder in the library #
# move a file in the library
library.get_file("/folder/file.txt").move_to(library.get_folder("/folder2"))
# move a folder in the library
library.get_folder("/folder").move_to(library.get_folder("/folder2"))
Delete a file or a folder from the library #
library.get_file("/path/to/item").delete()
library.get_folder("/path/to").get_file("/item").delete()
Reference documentation #
A handle to manage the library of a project It saves locally a copy of taxonomy to help navigate in the library All modifications done through this object and related library items are done locally and on remote. |