seedme (version 1.2.3)
index
/Volumes/data2/Projects/SeedMe/devel/python/seedme/seedme.py

seedme.py: Uploads, downloads and queries content at SeedMe.org.
This module provides command line interface as well as methods and api
for programmatic usage. It performs extensive sanity checks input data
and is kept upto date with REST api at SeedMe.org.
 
Usage:
1. See README.md file
   -or-
2. Visit https://bitbucket.org/seedme/seedme-python-client/overview

 
Modules
       
glob
json
logging
os
thirdparty.requests
subprocess
sys

 
Classes
       
__builtin__.object
SeedMe

 
class SeedMe(__builtin__.object)
    SeedMe class implements methods for using webservices
 
  Methods defined here:
__del__(self)
Delete SeedMe object
__init__(self)
Initializes state for SeedMe object
add_email(self, cid, email, notify=False)
Adds emails to an existing collection and notifies users.
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
email         : str, list or str, required
                space or comma separated email str or list of emails
notify        : bool, optional (default: False)
                send email notification to users about shared collection
add_file(self, cid, filepath, title='', description='', overwrite=False, poster='', fps=30, encode=True, transcode=True)
Uploads a file to an existing collection.
Returns a string which is a  JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
 
filepath      : str, required
                Path for file to upload
 
title         : str, optional
                Title for the file
 
description   : str, optional
                Description for the file
 
overwrite     : bool, optional (default: false)
                Overwrite existing files in the collection
                Global setting per execution for all files
                (not per file)
*'poster' : str, optional, *videos only
*'fps'        : float (default 30), *videos only
*'encode'     : bool, optional, *videos only
*'transcode'  : bool, optional, same as encode, *videos only
add_keyvalue(self, cid, keyvalue)
Adds a key-value pair to an existing collection.
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
keyvalue      : dict, required
                Key Value pairs for the collection
add_plot(self, cid, filepath, title='', description='', overwrite=False)
DEPRECATED use add_file method
Uploads a plot to an existing collection.
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
 
filepath      : str, required
                Path for file to upload
 
title         : str, optional
                Title for the file
 
description   : str, optional
                Description for the file
 
overwrite     : bool, optional (default: false)
                Overwrite existing plots in the collection
                Global setting per execution for all plots
                (not per file)
add_sequence(self, cid, filepath='', title='', description='', fps=30, encode=False, overwrite=False)
Uploads new or appends an image sequence to an existing collection.
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
 
filepath      : str or list or str, optional
                Path for file to upload
 
title         : str, required
                Title for the file
 
description   : str, optional
                Description for the file
 
fps           : float, optional (default 30)
                Frame rate for creating video
 
encode        : bool, optional
                Encode image sequence to video
 
overwrite     : bool, optional (default: false)
                Overwrite existing sequence files in the collection
                Global setting per execution for all sequences
                (not per file)
add_tag(self, cid, tag)
Adds a tag to an existing collection.
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
tag           : str or list of str, required
                Tag for the collection
add_ticker(self, cid, ticker)
Adds a ticker to an existing collection.
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
ticker        : str, required
                Text ticker for the collection
add_video(self, cid, filepath, poster='', title='', description='', fps=30, encode=True, transcode=True, overwrite=False)
DEPRECATED use add_file method
Uploads a video to an existing collection.
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
filepath      : str, required
                Path for file to upload
 
poster        : str, optional
                Path for poster file to upload
 
title         : str, optional
                Title for the file
 
description   : str, optional
                Description for the file
 
fps           : float (default is video's fps)
                Frame rate for creating video
 
encode        : bool, optional
                Transcode video
                (placebo same as encode)
 
transcode     : bool, optional
                Transcode video
 
overwrite     : bool, optional (default: false)
                Overwrite existing videos in the collection
                Global setting per execution for all videos
                (not per file)
create_collection(self, privacy='', sharing='', notify='', title='', description='', transfer='', overwrite=None, keyvalues=None, tags=None, tickers=None, files=None, sequences=None, plots=None, videos=None)
Creates a new collection at SeedMe.org
Returns a string which is a JSON array
Parameters
----------
privacy         : str, optional
                  Permissions to access collection
                  'private' (default) or 'group' or 'public'
 
sharing         : str or list of string, optional
                  space or comma delimimted string
                  or list of emails for sharing and notification
 
notify          : bool, optional (default: False)
                  send email to shared users about shared collection
 
title           : str, required
                  Title for the collection
 
description     : str, optional
                  Description for the collection
 
transfer        : string, optional
                  email to whom collection ownership will be transferred
 
overwrite       : bool OR dict, optional
                  Dictionary consisting of following key value pairs
                  'all_types' : bool, optional (default: False)
                  'files' : bool, optional (default: False)
                  'plots' : bool, optional (default: False)
                  'sequences' : bool, optional (default: False)
                  'videos' : bool, optional (default: False)
 
keyvalues       : dict, optional
                  Key Value pairs for the collection
 
tags            : str OR list of str, optional
                 tags for the collection
 
tickers         : str OR list of str, optional
                  Text tickers for the collection
 
files           : dict OR list of dict, optional
                  Dictionary consisting of following key value pairs
                  'filepath'    : str, required
                  'title'       : str, optional
                  'description' : str, optional
                  *'poster'     : str, optional, *videos only
                  *'fps'        : float (default 30), *videos only
                  *'encode'     : bool, optional, *videos only
 
sequences       : dict OR list of dict, optional
                  Dictionary consisting of following key value pairs
                  'filepath'    : str or list of str, required
                  'title'       : str, required
                  'description' : str, optional
                  'fps'         : float (default 30)
                  'encode'      : bool, optional
 
plots           : DEPRECATED use files instead
                  dict OR list of dict, optional
                  Dictionary consisting of following key value pairs
                  'filepath'    : str, required
                  'title'       : str, optional
                  'description' : str, optional
 
videos          : DEPRECATED use files instead
                  dict OR list of dict, optional
                  Dictionary consisting of following key value pairs
                  'filepath'    : str, required
                  'poster'      : str, optional
                  'title'       : str, optional
                  'description' : str, optional
                  'fps'         : float (default 30)
                  'encode'      : bool, optional
delete(self, cid, files=None, nodes=None)
Deletes collection or collection's content
Returns JSON array
 
**************************
Delete collection examples
**************************
Delete a collection id 666 and all its content
delete(666)
 
Delete a file with name 1234.png in collection id 666
delete(666, files='1234.png')
 
Delete a node with id 1234 in collection id 666
delete(666, nodes=1234)
 
 
Parameters
----------
cid             : int, required
                  Collection ID to delete
download(self, cid=None, content=None, path=None, retry=1, interval=60, overwrite=False)
Download items
 
Parameters
----------
cid             : int, required
                  Collection ID for download
 
content         : Which content to download
                  Choice of one of the following, required
                  wildcard string: download any files that match given string
                  'all': download all files in collection
                  'video': download only videos in collection
                  'original': download source video if one was uploaded
                  'native': download superb quality video if it was encoded
                  'highest': download highest quality video
                  'high': download high quality video
                  'medium': download medium quality video
                  'low': download low quality video
                  'lowest': download lowest quality video
                  Note: only one of native or original video is available
 
path            : str, optional
                  Path for downloading content
                  Default: ~/Downloads or HOME/Downloads
                  Special case: When downloading a single file user could
                  provide path with output filename e.g. ~/Downloads/abc
                  This will download the file as abc.ext at ~/Downloads
 
retry           : int, optional
                  number of times to retry attempts for downloading
 
interval        : int, optional
                  number of seconds between retry > 30
                  Default: 60
 
overwrite       : bool, optional
                  Overwrite local existing files
encode_sequence(self, cid, title, fps=30)
Creates a video from an existing sequence
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
 
title         : str, required
                Title must be identical to an existing sequence title
 
fps           : float, optional (default 30)
                Frame rate for creating video
encode_video(self, cid, title, fps=30)
Alias function for transcode_video
notify(self, cid, email=None)
Notify users about shared collection via email
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
email         : str, list or str
                space or comma separated email str or list of emails
query(self, cid=None, keyvalues=None, content=None, tail=None)
Queries and retrieves content from user's collections
Returns JSON array
 
*********************
Query All Collections
*********************
query(): Returns list of users collection
query(keyvalues="ssid:1234"): Returns list of all collection that match
                              all specified key values
************************
Query Single Collections
************************
query(cid=666, list='all'): Returns all content for collection ID 666
query(cid=666, list='tic'): Returns all tickers for collection ID 666
query(cid=666, list='tic', tail=5): Returns last 5 tickers for ID 555
 
 
Parameters
----------
cid   : bool OR int, required
                  Collection ID to query
 
keyvalues       : colon delimited string or dict, optional
                  Key Value pairs to search in all user's collection
                  when multiple key values are specified they are used
                  with AND condition. The function returns a list of
                  collections that match all specified key values.
                  Note: This option must be used without other arguments
 
content    : str, optional (Requires cid set as colleciton ID)
                  Choice of one of the following
                  ['all', 'keyvalue', 'kv', 'tic', 'ticker', 'url']
                  Default: all
                  Note: this option can only be used with cid
 
tail            : int, optional (Requires content option)
                  Last n items to list.
                  Note: this option can only be used in conjunction with
                  content as kv OR tic OR url
set_auth_via_file(self, my_auth_file_path)
Sets authorization with a file containing username:apikey
Use this method when using this module via script
Parameters
----------
my_auth_file_path : JSON file
                    Absolute path to file containing the following
                    {"username":"YourUserName", "apikey":"YourApiKey"}
set_auth_via_string(self, my_username, my_apikey)
Sets authorization with username and apikey
Parameters
----------
my_username : str
              Your username for SeedMe.org
 
my_apikey   : str
             Your apikey for SeedMe.org
set_base_url(self, custom_url)
Overide and set base URL for web services
Useful only for interacting with older versions of webservices API
Parameters
----------
custom_url : str
             Web Services URL for SeedMe.org
set_connection_timeout(self, duration=60)
Sets connection timeout duration for HTTP POST and GET
Parameters
----------
duration : int (seconds)
set_console_log(self, state)
Sets console log state.
Note: console output is ON by default
Parameters
----------
state : bool
        True or False
set_curl_path(self, my_path)
Sets curl path
Parameters
----------
my_path : str
          Absolute path to curl executible
set_dry_run(self)
Performs sanity checks on all inputs locally,
except authorization which requires server side communication
set_file_log(self, state, filepath=None)
Sets file log state and filepath
Parameters
----------
state    : bool
           True or False
filepath : str
           filepath to log file
set_overwrite(self, all_types=False, files=False, plots=False, sequences=False, videos=False)
Sets overwrite mode for all, file, plot, sequence, video
Parameters
----------
all_types : bool
           Global overwrite for all content types
files     : bool
           Overwrite file if it exist
plots     : bool
           Overwrite plot if it exist
seqeunces : bool
           Overwrite sequence file if it exist
videos    : bool
           Overwrite video file if it exist
set_post_method(self, my_post_method)
Sets POST method
Parameters
----------
my_post_method : str
                 Valid options 'requests' or 'curl'
set_read_timeout(self, duration=None)
Sets read timeout duration for HTTP POST and GET
Parameters
----------
duration : int (seconds)
set_ssl(self, state=True)
Sets SSL on of off
This must be never turned off. If done please reset your APIKEY ASAP
Parameters
----------
state : boolean
set_ssl_cert(self, path)
Sets path to SSL certificate file to be used for secure communication
   This is only needed in special cases when
   * default certifcate cacert.pem is not found in default system path
   * default cacert.pem certifacate does not work in firewalled zones
   * REQUESTS_CA_BUNDLE environment variable to cert path is not set
Parameters
----------
path : string (path to file)
share(self, cid, email, notify=False)
Alias function for add_email
show_auth_in_curl_commands(self)
Sets POST method to curl and shows curl command line options
show_curl_commands(self)
Sets POST method to curl and shows curl command line options
transcode_video(self, cid, title, fps=30)
Transcodes an existing video
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
 
title         : str, required
                Title must be identical to an existing video title
 
fps           : float (default 30)
                Frame rate for creating video
update_collection(self, collection_id, privacy='', sharing='', notify='', title='', description='', transfer='', overwrite=None, keyvalues=None, tags=None, tickers=None, files=None, sequences=None, plots=None, videos=None)
Updates any content for an existing collection at SeedMe.org
Returns a string which is a JSON array
Parameters
----------
collection_id   : int, required
                  Collection ID to update
 
privacy         : str, optional
                  Permissions to access collection
                  'private' (default) OR 'group' OR 'public'
 
sharing         : str, optional
                  space OR comma delimimted string
                  or list of emails for sharing and notification
 
notify          : bool, optional (default: False)
                  send email to shared users about shared collection
 
title           : str, optional
                  Title for the collection
 
description     : str, optional
                  Description for the collection
 
transfer        : string, optional
                  email to whom collection ownership will be transferred
 
overwrite       : bool OR dict, optional
                  Dictionary consisting of following key value pairs
                  'all_types' : bool, optional (default: False)
                  'files' : bool, optional (default: False)
                  'plots' : bool, optional (default: False)
                  'sequences' : bool, optional (default: False)
                  'videos' : bool, optional (default: False)
 
keyvalues       : dict, optional
                  Key Value pairs for the collection
 
tags            : str OR list of str, optional
                 tags for the collection
 
tickers         : str OR list of str, optional
                  Text tickers for the collection
 
files           : dict OR list of dict, optional
                  Dictionary consisting of following key value pairs
                  'filepath'    : str, required
                  'title'       : str, optional
                  'description' : str, optional
                  *'poster'     : str, optional, *videos only
                  *'fps'        : float (default 30), *videos only
                  *'encode'     : bool, optional, *videos only
 
sequences       : dict OR list of dict, optional
                  Dictionary consisting of following key value pairs
                  'filepath'    : str or list of str, required
                  'title'       : str, optional
                  'description' : str, optional
                  'fps'         : float (default 30)
                  'encode'      : bool, optional
 
plots           : DEPRECATED use files instead
                  dict OR list of dict, optional
                  Dictionary consisting of following key value pairs
                  'filepath'    : str, required
                  'title'       : str, optional
                  'description' : str, optional
 
videos          : DEPRECATED use files instead
                  dict OR list of dict, optional
                  Dictionary consisting of following key value pairs
                  'filepath'    : str, required
                  'poster'      : str, optional
                  'title'       : str, optional
                  'description' : str, optional
                  'fps'         : float (default 30)
                  'encode'      : bool, optional
update_description(self, cid, description)
Updates description of an existing collection
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
description   : str, required
                New description for the collection
update_privacy(self, cid, privacy, email=None, notify=False)
Updates privacy, adds emails and notifies users
for an existing collection
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
privacy       : str, required
                privacy for the collection (public, group, private)
email         : str, list or str, optional
                space or comma separated email str or list of emails
notify        : bool, optional (default: False)
                send email notification to users about shared collection
update_title(self, cid, title)
Updates title of an existing collection
Returns a string which is a JSON array
Parameters
----------
collection_id : int, required
                Collection ID to update
title         : str, required
                New title for the collection
version(self)
Returns a dict with following keys
module_version,
api_version,
service url

Static methods defined here:
extract_cid(result)
DEPRECATED use get_id(result) method
Returns int for (success OR partial) or none
Wraps extract_cid global function
Parameters
----------
result : string in JSON format
extract_status(result)
DEPRECATED use get_status(result) method
Returns success, partial, failure or None
Wraps extract_status global function
Parameters
----------
result : string in JSON format
get_id(result)
Returns int for (success OR partial) or none
Wraps get_id global function
Parameters
----------
result : string in JSON format
get_message(result)
Returns string message or None
Wraps get_message global function
Parameters
----------
result : string in JSON format
get_status(result)
Returns success, partial, failure or None
Wraps get_status global function
Parameters
----------
result : string in JSON format
get_url(result)
Returns string (url to the collection)
Wraps get_url global function
Parameters
----------
result : string in JSON format
set_log_level(level)
Sets logging level
Parameters
----------
level : DEBUG, INFO, WARNING, ERROR, CRITICAL
test_default_auth()
Tests whether default authorization file is usable
Returns: Boolean

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
extract_cid(result)
DEPRECATED use get_id(result) method
Extracts collection id from JSON string
Returns int or none
Parameters
----------
result : string in JSON format
extract_status(result)
DEPRECATED use get_status(result) method
Extracts status from JSON string
Returns success, partial, failure or None
Parameters
----------
result : string in JSON format
get_id(result)
Extracts collection id from JSON string
Returns int or none
Parameters
----------
result : string in JSON format
get_message(result)
Gets message from JSON string when status is partial or failure
When status is successful None is returned
Useful for extracting and printing problem messages
Returns string or None
Parameters
----------
result : string in JSON format
get_status(result)
Gets status from JSON string
Returns success, partial, failure or None
Parameters
----------
result : string in JSON format
get_url(result)
Gets collection URL on success or partial success
Returns string (url to the collection)
Parameters
----------
result : string in JSON format
human_readable_size(nbytes)
Calculates and returns human readable file size
Returns string
main()
CLI - Uploads content to SeedMe.org in command line mode.
sleep(...)
sleep(seconds)
 
Delay execution for a given number of seconds.  The argument may be
a floating point number for subsecond precision.
test_default_auth()
Tests whether default authorization file is usable
Returns: Boolean

 
Data
        __author__ = 'Amit Chourasia'
__status__ = 'Production'
__version__ = '1.2.3'
log = <logging.Logger object>
null_handler = <seedme._NullHandler object>

 
Author
        Amit Chourasia