API Reference

Repository Inteface

class sandglass.clientrepository.ClientRepository(data_dir=None, root_dir=None)
add(*args, **kwargs)

Add files to be tracked.

changed(*args, **kwargs)

Return ChangeSet object with information about changes performed on tracked files.

commit(*args, **kwargs)

Performs a commit.

diff(*args, **kwargs)

Show diff between two revisions. The output can be limited by passing a list of files. If ‘old_commit’ is not specified, use the branch head commit. If ‘new_commit’ is not specified, use working tree state (not really a commit).

dump(*args, **kwargs)

Get file content at a given commit. If the commit is not specified, use the last one.

get_attributes(commit=None)

Get AttributeSet with information taken from a given commit.

init(force=False)

Initialize new repository. If the repository is already initialized, ‘force’ has to be set to True.

real_filename(internal_path)

Convert name of file stored in repository to real name on filesystem.

recover(*args, **kwargs)

Recover file(s) including attributes from repository. If the commit is not given, use the last one.

remote(*args, **kwargs)

Set up a synchronization with remote server and return an updated list of servers.

repo_filename(real_path)

Opposite of real_filename(). Returns virtual repository path.

sync(*args, **kwargs)

Run synchronization with remote server.

tracked(*args, **kwargs)

Return list of tracked files.

untrack(*args, **kwargs)

Remove files from the list of tracked files.

class sandglass.serverrepository.ServerRepository(data_dir, uid, gid)
delete(*args, **kwargs)

Delete client history.

init(force=False)

Initialize server repository. If the repository is already initialized, ‘force’ has to be set to True.

log(*args, **kwargs)

Show client history.

pick(*args, **kwargs)
real_filename(repo_filename)
repo_filename(real_filename)
status()

Return a dictionary with information about synchronized clients.

Example result: { “alice”: (“1234567”, “2011-01-01 01:01:01”), “bob”: (“abcdefg”, “2011-02-02 02:02:02”) }

class sandglass.repository.Repository

This is a base class for ClientRepository and ServerRepository.

diff(*args, **kwargs)

Show diff between two revisions. The output can be limited by passing a list of files.

dump(*args, **kwargs)

Get file content at a given commit.

get_attributes(revision)

Load file attributes from repository at a given commit.

is_initialized()

Return True if the repository is initialized.

log(*args, **kwargs)

Get commit history. The history can be limited by passing a list of files.

real_filename(repo_filename)

Convert repository filename to real filename. Opposite of repo_filename.

repo_filename(real_filename)

Convert real filename to repository filename. Opposite of repo_filename.

show(*args, **kwargs)

Show content of given commit (as a diff). The output can be limited by passing a list of files.

sandglass.repository.need_initialized(method)

Decorator function. Raise exception on method call if the repository is not initialized.

sandglass.repository.need_not_initialized(method)

Decorator function. Raise exception on method call if the repository is initialized.

class sandglass.interface.Sandglass(**kwargs)
add(files, config_only=True)

Add files or directories to the repository.

If ‘config_only’ is set to True, only configuration files (according to package manager database) will be added and the other will be ignored. The setting of this option does not have effect on adding files.

add_changed(files)
get_package_files(package)

Return list of configuration files owned by given package.

rm(files)

Remove files from the list of versioned files.

class sandglass.interface.SandglassBase
class sandglass.interface.SandglassServer(data_dir=None, owner='sglserver:sglserver')

Runtime Data

class sandglass.cache.Cache(name, public=True)

Universal class for simple object storing on local filesystem. Can be used as database or cache. Uses Python pickle as internal storage.

data

Get object stored in cache (shallow copy).

Note that data structures obtained using this method are not saved to cache after any modifications. To save the state of the object to cache, use cache.data = data or cache.save().

save()

Save the object to the cache.

saved_at()

Return timestamp of the last save operation.

classmethod set_location(path)

Set location for cache files.

sandglass.cache.set_location(path)
class sandglass.config.Config(filename=None)
get(key, default=None)
getboolean(key, default=False)
getfloat(key, default=0.0)
getint(key, default=0)
sandglass.config.get_instance()
class sandglass.autocommit.Autocommit
is_enabled()
is_stalled(package)
is_stalled_all()
message(changeset, package)

Get a message describing time of next autocommit for a given changeset.

set_auto(package)
set_auto_all()
set_stall(package)
set_stall_all()
time(changeset)

Get time of an autocommit for a given ChangeSet.

sandglass.autocommit.get_instance()

Distribution Specificities

class sandglass.distinfo.DistInfo
sandglass.distinfo.get_instance()
class sandglass.distinfo.base.DistInfoBase
config_files(prefix=None, must_exist=True, ignore_blacklist=False)
file_package(path)
invalidate_cache()
is_config(path)
package_files(package, prefix=None, must_exist=True, ignore_blacklist=False)
class sandglass.distinfo.fedora.DistInfo
invalidate_cache()

File Information

Storing file attributes (permissions, owner, SELinux context).

class sandglass.fileinfo.attributes.Attribute(filename, mode=0, user=None, group=None, context=None, package=None)

Representation of attributes of one file.

Stores file name, owning package, ownerships, permissions and SELinux context.

diff(other)

Get difference between two file attributes. Both Attribute objects have to refer to the same file. Return appropriate changes.Change object if the attributes differ. Otherwise return None.

classmethod from_string(data)

Convert string to Attribute object.

classmethod gen_diff_headers(old, new)
load()

Read mode, permission and context of the file.

save(filename=None)

Apply mode, permissions and context to the file.

to_string()

Convert Attribute object to string representation.

class sandglass.fileinfo.attributes.AttributeSet(file_list=None)
files()
load(filename)
load_s(data)
refresh()
save(filename)
class sandglass.fileinfo.changes.Change(last_change=None)

Base class for any kind of change held on filesystem.

detailed_str()

Return a string with detailed information about the change.

merge_old(old)

Merge the old change into new one (self).

name()

Return a string with the name of the change.

class sandglass.fileinfo.changes.ChangeSet

The aggregation of changes (class Change).

add_or_update(file, new_change)

Add another Change object to the list of changes performed on one file. Any old Change object of the same type (same base class) is removed before.

add_or_update_list(file, changes)

Replace the list of all changes performed on one file.

by_package()

Group changes by package name. Return a dictionary with package names as keys and ChangeSet objects as values. Shallow copies of the lists are performed.

files()

List of files whose changes this object holds.

merge_old(old)

Merge this object with another one. The changes stored in the second object are considered old. It might be necessary to confront the state of the changes with the old state. The action is performed by calling ‘merge’ method on matching objects (of Change type).

time_first_change()

Get timestamp of the first change in the list of changes.

time_last_change()

Get timestamp of the last change in the list of changes.

class sandglass.fileinfo.changes.Context(old, new)

Information about the change of the file SELinux context.

detailed_str()
merge_old(old)
name()
class sandglass.fileinfo.changes.Delete

Information about the file deletion.

detailed_str()
name()
class sandglass.fileinfo.changes.Mode(old=0, new=0)

Information about the change of the file mode.

detailed_str()
merge_old(old)
name()
class sandglass.fileinfo.changes.Modify(added=0, deleted=0, mtime=None)

Information about the change in a file.

detailed_str()
name()
class sandglass.fileinfo.changes.Owner(old=[None, None], new=[None, None])

Information about the change of the file ownership.

detailed_str()
merge_old(old)
name()

Exceptions

exception sandglass.exceptions.CommandFailed
exception sandglass.exceptions.DistributionNotSupported
exception sandglass.exceptions.IOError
exception sandglass.exceptions.InvalidOperation
exception sandglass.exceptions.InvalidRevision(message)
exception sandglass.exceptions.RepositoryFormat(message)
exception sandglass.exceptions.RepositoryInitialization(message)
exception sandglass.exceptions.SandglassException
exception sandglass.exceptions.SandglassExceptionWithMessage(message)
exception sandglass.exceptions.UnexpectedResult(message)

Design Patterns

class sandglass.base.Flyweight

Flyweight design pattern.

classmethod get_instance(name=None)
class sandglass.base.Singleton

Singleton design pattern.

classmethod get_instance()

Generic Utilities

class sandglass.config.Config(filename=None)
get(key, default=None)
getboolean(key, default=False)
getfloat(key, default=0.0)
getint(key, default=0)
sandglass.config.get_instance()
class sandglass.utils.Command(args)
exit_code

Process exit code.

stderr

Process error output.

stdout

Process output.

sandglass.utils.abs_path(path)

Convert path to absolute and normalized path.

sandglass.utils.file_mtime(filename, must_exist=True)
sandglass.utils.files_from_dir(path)

Create list of files in given directory (recursively).

sandglass.utils.hostname()
sandglass.utils.is_dir(path)

Return True if specified path is real directory (not symlink), False otherwise.

sandglass.utils.secure_makedirs(*args, **kwargs)

Create directories recursively. Newly created directories are set user-accessible only. Works the same as Python ‘os.makedirs’ function.

sandglass.utils.secure_open(filename, *args, **kwargs)

Open file handle. If the file is created, set it user-accessible only. Works the same as Python builtin ‘open’ function

sandglass.utils.temp_file()

Return the name of new temporary file created by tempfile.mkstemp(). The file will be automatically deleted at program termination.

sandglass.utils.time_ago(timestamp)
sandglass.utils.time_relative(timestamp)
sandglass.utils.time_remains(timestamp)
sandglass.utils.timestamp_to_str(timestamp, format=None)

GitPython Overrides

class sandglass.override.GitCmd(working_dir=None)
execute(*args, **kwargs)
class sandglass.override.Repo(repo_dir, work_dir)

Table Of Contents

Previous topic

Server Tutorial

This Page