materials_commons.cli.treedb module

class materials_commons.cli.treedb.LocalTree(proj_local_path)[source]

Bases: materials_commons.cli.treedb.TreeTable

Store information on files and directories in the working tree

Values:

id: None, (always None) # TODO: clean up ‘id’, ‘parent_id’, ‘parent_path’ parent_id: None, (always None) path: str, relative path including project directory (matches Materials Commons ‘path’) name: str, file or directory name otype: str, ‘file’ or ‘directory’ mtime: real, file or directory modify time (s since epoch) checktime: real, last time the record was updated (s since epoch) size: integer, file size checksum: str, md5 hash parent_path: str, path of parent directory (or none for ‘top’)

Arguments: proj_local_path: str

Path to Materials Commons project directory, for storing sqlite db file

static default_print_fmt()[source]
insert_non_existent(path, checktime=None, verbose=False)[source]

Do not insert non-existent

needs_update(existing)[source]
static tablename()[source]
static treename()[source]
class materials_commons.cli.treedb.RemoteTree(proj, updatetime)[source]

Bases: materials_commons.cli.treedb.TreeTable

Store information on files and directories in the Materials Commons project

Values:

id: str, Materials Commons id string parent_id: str, Materials Commons id string path: str, path including project directory name: str, file or directory name otype: str, ‘file’ or ‘directory’ mtime: real, file or directory modify time (s since epoch) checktime: real, last time the record was updated (s since epoch) size: integer, file size checksum: str, md5 hash parent_path: str, path of parent directory (or none for ‘top’)

Arguments: proj_local_path: str

Path to Materials Commons project directory, for storing sqlite db file

static default_print_fmt()[source]
insert_non_existent(path, checktime=None, verbose=False)[source]

Do insert non-existent

needs_update(existing)[source]
static tablename()[source]
static treename()[source]
class materials_commons.cli.treedb.TreeTable(proj_local_path)[source]

Bases: materials_commons.cli.sqltable.SqlTable

Store information on files and directories in a tree

This is a base class. Derived classes must implement:

  • @staticmethod default_print_fmt(): list of tuple, see an example

  • @staticmethod treename(): str, tree label for printing (‘remote’, ‘local’)

  • @staticmethod tablename(): str, tree table name in sqlite database (‘remotetree’, ‘localtree’)

  • needs_update(self, existing): bool, check if record needs updating

  • _check(self, path, get_children=True, parent_path=None): (dir, children), see an example

Values:

path: str, path including project directory name: str, file or directory name parent_path: str, path of parent directory (or None for ‘top’) otype: str, ‘file’ or ‘directory’ mtime: real, file or directory modify time (s since epoch) checktime: real, last time the record was updated (s since epoch) size: integer, file size checksum: str, md5 hash id: str, ID string, depends on type of tree. For RemoteTree this is the Materials Commons

id. For LocalTree this is None.

parent_id: str, ID string, depends on type of tree. For RemoteTree this is the Materials

Commons id. For LocalTree this is None.

Parameters

proj_local_path – str Path to Materials Commons project directory, for storing sqlite db file

delete_by_path(path, recurs=False, verbose=False)[source]

Delete individual entry by path

Parameters
  • path – str The Materials Commons path of the file_or_dir to delete.

  • recurs – bool If True, delete children recursively

  • verbose – bool If True, print status.

select_all(fetchsize=1000)[source]

Select all records

Yields

sqlite3.Row or None, if no records left

select_by_id(id)[source]

Select record by id

Returns

sqlite3.Row or None

select_by_parent_id(parent_id)[source]

Select records by parent_id

Returns

List of sqlite3.Row

select_by_parent_path(parent_path)[source]

Select records by parent_path

Returns

List of sqlite3.Row

select_by_path(path)[source]

Select records by path

Returns

List of sqlite3.Row

static tablecolumns()[source]
update(path, get_children=True, recurs=False, verbose=False, force=False)[source]

Update tree table to accurately reflect a particular directory

Parameters
  • path – str Materials Commons path to the directory to update (includes project directory).

  • get_children – bool If True, also update children files and directories.

  • recurs – bool If True, updating children is done recursively.

  • verbose – bool If True, print status.

walk(path, topdown=True)[source]

Yields (parent, dirs, files) records recursively starting from directory at path

materials_commons.cli.treedb.do_with_queue(f, queue)[source]