the other jimmy / mbed-sdk-tools

Fork of mbed-sdk-tools by mbed official

Embed: (wiki syntax)

« Back to documentation index

sources::utils Namespace Reference

sources::utils Namespace Reference

Data Structures

class  ToolException
class  NotSupportedException

Functions

def compile_worker
def cmd
def run_cmd
def run_cmd_ext
def is_cmd_valid
def is_exec
def find_cmd_abspath
def mkdir
def copy_file
def delete_dir_files
def get_caller_name
def error
def rel_path
def split_path
def get_path_depth
def args_error
def construct_enum
def check_required_modules
def dict_to_ascii
def json_file_to_dict
def argparse_force_type
def argparse_many
def argparse_filestring_type
def argparse_profile_filestring_type
def columnate
def argparse_dir_not_parent
def argparse_deprecate
def print_large_string

Detailed Description

mbed SDK
Copyright (c) 2011-2013 ARM Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Function Documentation

def sources::utils::argparse_deprecate (   replacement_message )
fail if argument is provided with deprecation warning

Definition at line 491 of file utils.py.

def sources::utils::argparse_dir_not_parent (   other )
fail if argument provided is a parent of the specified directory

Definition at line 477 of file utils.py.

def sources::utils::argparse_filestring_type (   string )
An argument parser that verifies that a string passed in corresponds
to a file

Definition at line 430 of file utils.py.

def sources::utils::argparse_force_type (   case )
validate that an argument passed in (as string) is a member of the list
of possible arguments after converting it's case.

Definition at line 400 of file utils.py.

def sources::utils::argparse_many (   func )
An argument parser combinator that takes in an argument parser and
creates a new parser that accepts a comma separated list of the same thing.

Definition at line 421 of file utils.py.

def sources::utils::argparse_profile_filestring_type (   string )
An argument parser that verifies that a string passed in is either
absolute path or a file name (expanded to
mbed-os/tools/profiles/<fname>.json) of a existing file

Definition at line 439 of file utils.py.

def sources::utils::args_error (   parser,
  message 
)
Abort with an error that was generated by the arguments to a CLI program

Positional arguments:
parser - the ArgumentParser object that parsed the command line
message - what went wrong

Definition at line 283 of file utils.py.

def sources::utils::check_required_modules (   required_modules,
  verbose = True 
)
Function checks for Python modules which should be "importable"
    before test suite can be used.
    @return returns True if all modules are installed already

Definition at line 303 of file utils.py.

def sources::utils::cmd (   command,
  check = True,
  verbose = False,
  shell = False,
  cwd = None 
)
A wrapper to run a command as a blocking job

Definition at line 64 of file utils.py.

def sources::utils::columnate (   strings,
  separator = ",
  chars = 80 
)
render a list of strings as a in a bunch of columns

Positional arguments:
strings - the strings to columnate

Keyword arguments;
separator - the separation between the columns
chars - the maximum with of a row

Definition at line 452 of file utils.py.

def sources::utils::compile_worker (   job )
Standard task runner used for compiling

Positional argumets:
job - a dict containing a list of commands and the remaining arguments
      to run_cmd

Definition at line 36 of file utils.py.

def sources::utils::construct_enum (   enums )
Create your own pseudo-enums

Keyword arguments:
* - a member of the Enum you are creating and it's value

Definition at line 294 of file utils.py.

def sources::utils::copy_file (   src,
  dst 
)
Implement the behaviour of "shutil.copy(src, dst)" without copying the
permissions (this was causing errors with directories mounted with samba)

Positional arguments:
src - the source of the copy operation
dst - the destination of the copy operation

Definition at line 175 of file utils.py.

def sources::utils::delete_dir_files (   directory )
A function that does rm -rf

Positional arguments:
directory - the directory to remove

Definition at line 189 of file utils.py.

def sources::utils::dict_to_ascii (   dictionary )
Utility function: traverse a dictionary and change all the strings in
the dictionary to ASCII from Unicode. Useful when reading ASCII JSON data,
because the JSON decoder always returns Unicode string. Based on
http://stackoverflow.com/a/13105359

Positional arguments:
dictionary - The dict that contains some Unicode that should be ASCII

Definition at line 333 of file utils.py.

def sources::utils::error (   msg )
Fatal error, abort hard

Positional arguments:
msg - the message to print before crashing

Definition at line 215 of file utils.py.

def sources::utils::find_cmd_abspath (   command )
Returns the absolute path to a command.
    None is returned if no absolute path was found.

Positional arguhments:
command - the command to find the path of

Definition at line 145 of file utils.py.

def sources::utils::get_caller_name (   steps = 2 )
When called inside a function, it returns the name
of the caller of that function.

Keyword arguments:
steps - the number of steps up the stack the calling function is

Definition at line 204 of file utils.py.

def sources::utils::get_path_depth (   path )
Given a path, return the number of directory levels present.
    This roughly translates to the number of path separators (os.sep) + 1.
    Ex. Given "path/to/dir", this would return 3
    Special cases: "." and "/" return 0

Positional arguments:
path - the path to calculate the depth of

Definition at line 263 of file utils.py.

def sources::utils::is_cmd_valid (   command )
Verify that a command exists and is executable

Positional arguments:
command - the command to check

Definition at line 120 of file utils.py.

def sources::utils::is_exec (   path )
A simple check to verify that a path to an executable exists

Positional arguments:
path - the executable

Definition at line 136 of file utils.py.

def sources::utils::json_file_to_dict (   fname )
Read a JSON file and return its Python representation, transforming all
the strings from Unicode to ASCII. The order of keys in the JSON file is
preserved.

Positional arguments:
fname - the name of the file to parse

Definition at line 352 of file utils.py.

def sources::utils::mkdir (   path )
a wrapped makedirs that only tries to create a directory if it does not
exist already

Positional arguments:
path - the path to maybe create

Definition at line 164 of file utils.py.

def sources::utils::print_large_string (   large_string )
Breaks a string up into smaller pieces before print them

This is a limitation within Windows, as detailed here:
https://bugs.python.org/issue11395

Positional arguments:
large_string - the large string to print

Definition at line 498 of file utils.py.

def sources::utils::rel_path (   path,
  base,
  dot = False 
)
Relative path calculation that optionaly always starts with a dot

Positional arguments:
path - the path to make relative
base - what to make the path relative to

Keyword arguments:
dot - if True, the path will always start with a './'

Definition at line 225 of file utils.py.

def sources::utils::run_cmd (   command,
  work_dir = None,
  chroot = None,
  redirect = False 
)
Run a command in the forground

Positional arguments:
command - the command to run

Keyword arguments:
work_dir - the working directory to run the command in
chroot - the chroot to run the command in
redirect - redirect the stderr to a pipe to be used later

Definition at line 74 of file utils.py.

def sources::utils::run_cmd_ext (   command )
A version of run command that checks if the command exists befor running

Positional arguments:
command - the command line you are trying to invoke

Definition at line 108 of file utils.py.

def sources::utils::split_path (   path )
spilt a file name into it's directory name, base name, and extension

Positional arguments:
path - the file name to split

Definition at line 252 of file utils.py.