starcluster.utils

Package starcluster :: Module utils |
[hide private]
[frames] | no frames]

# Module utils

source code

Utils module for StarCluster

Classes | [hide private]
| AttributeDict Subclass of dict that allows read-only attribute-like access to dictionary key/values

Functions | [hide private]
ipy_shell(local_ns=None) user_ns | source code
print_timing(msg=None) Decorator for printing execution time (in mins) of a function Optionally takes a user-friendly msg as argument. | source code
is_valid_device(dev) Checks that dev matches the following regular expression: /dev/sd[a-z]$ | source code
is_valid_partition(part) Checks that part matches the following regular expression: /dev/sd[a-z][1-9][0-9]?$ | source code
is_valid_bucket_name(bucket_name) Check if bucket_name is a valid S3 bucket name (as defined by the AWS docs): | source code
is_valid_image_name(image_name) Check if image_name is a valid AWS image name (as defined by the AWS docs) | source code
make_one_liner(script) Returns command to execute python script as a one-line python program | source code
is_url(url) Returns True if the provided string is a valid url | source code
is_iso_time(iso) Returns True if provided time can be parsed in iso format to a datetime tuple | source code
iso_to_datetime_tuple(iso) Converts an iso time string to a datetime tuple | source code
datetime_tuple_to_iso(tup) Converts a datetime tuple to iso time string | source code
get_elapsed_time(past_time) | source code
iso_to_unix_time(iso) | source code
iso_to_javascript_timestamp(iso) Convert dates to Javascript timestamps (number of milliseconds since January 1st 1970 UTC) | source code
iso_to_localtime_tuple(iso) | source code
permute(a) Returns generator of all permutations of a | source code
has_required(programs) Same as check_required but returns False if not all commands exist | source code
check_required(programs) Checks that all commands in the programs list exist. | source code
which(program) Returns the path to the program provided it exists and is on the system's PATH | source code
tailf(filename) Constantly displays the last lines in filename Similar to 'tail -f' unix command | source code
v2fhelper(v, suff, version, weight) | source code
version_to_float(v) Convert a Mozilla-style version string into a floating-point number 1.2.3.4, 1.2a5, 2.3.4b1pre, 3.0rc2, etc | source code
program_version_greater(ver1, ver2) Return True if ver1 > ver2 using semantics of comparing version numbers | source code
test_version_to_float() | source code
get_arg_spec(func) Convenience wrapper around inspect.getargspec | source code
chunk_list(ls, items=8) iterate through 'chunks' of a list. | source code

Variables | [hide private]
| __package__ = ``'``starcluster``'``

Function Details | [hide private]

### print_timing(msg=None) | source code
    Decorator for printing execution time (in mins) of a function
    Optionally takes a user-friendly msg as argument. This msg will
    appear in the sentence "[msg] took XXX mins". If no msg is specified,
    msg will default to the decorated function's name. e.g:

    @print_timing
    def myfunc():
        print 'Running myfunc'
    >>> myfunc()
    Running myfunc
    myfunc took 0.000 mins

    @print_timing('My function')
    def myfunc():
        print 'Running myfunc'
    >>> myfunc()
    Running myfunc
    My function took 0.000 mins

### is_valid_bucket_name(bucket_name) | source code
    Check if bucket_name is a valid S3 bucket name (as defined by the AWS
    docs):

    1. 3 <= len(bucket_name) <= 255
    2. all chars one of: a-z 0-9 .  _ -
    3. first char one of: a-z 0-9
    4. name must not be a valid ip

### is_valid_image_name(image_name) | source code
    Check if image_name is a valid AWS image name (as defined by the AWS docs)

    1. 3<= len(image_name) <=128
    2. all chars one of: a-z A-Z 0-9 ( ) . - / _

### make_one_liner(script) | source code
    Returns command to execute python script as a one-line python program

    e.g.

        import os
        script = '''
        import os
        print os.path.exists('hi')
        '''
        os.system(make_one_liner(script))

    Will print out:

        <module 'os' from ...>
        False

### permute(a) | source code
    Returns generator of all permutations of a

    The following code is an in-place permutation of a given list, implemented
    as a generator. Since it only returns references to the list, the list
    should not be modified outside the generator. The solution is
    non-recursive, so uses low memory. Work well also with multiple copies of
    elements in the input list.

    Retrieved from:
        http://stackoverflow.com/questions/104420/         how-to-generate-all-permutations-of-a-list-in-python

### check_required(programs) | source code
Checks that all commands in the programs list exist. Returns True if all commands exist and raises exception.CommandNotFound if not.

### which(program) | source code
Returns the path to the program provided it exists and is on the system's PATH retrieved from code snippet by Jay: http://stackoverflow.com/questions/377017/ test-if-executable-exists-in-python

### get_arg_spec(func) | source code
Convenience wrapper around inspect.getargspec Returns a tuple whose first element is a list containing the names of all required arguments and whose second element is a list containing the names of all keyword (optional) arguments.

### chunk_list(ls, items=8) | source code
iterate through 'chunks' of a list. final chunk consists of remaining elements if items does not divide len(ls) evenly. items - size of 'chunks'