Rtos API example

Embed: (wiki syntax)

« Back to documentation index

tools::utils Namespace Reference

tools::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
def intelhex_offset

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 tools::utils::argparse_deprecate (   replacement_message )
fail if argument is provided with deprecation warning

Definition at line 492 of file utils.py.

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

Definition at line 478 of file utils.py.

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

Definition at line 431 of file utils.py.

def tools::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 401 of file utils.py.

def tools::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 422 of file utils.py.

def tools::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 440 of file utils.py.

def tools::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 284 of file utils.py.

def tools::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 304 of file utils.py.

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

Definition at line 65 of file utils.py.

def tools::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 453 of file utils.py.

def tools::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 37 of file utils.py.

def tools::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 295 of file utils.py.

def tools::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 176 of file utils.py.

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

Positional arguments:
directory - the directory to remove

Definition at line 190 of file utils.py.

def tools::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 334 of file utils.py.

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

Positional arguments:
msg - the message to print before crashing

Definition at line 216 of file utils.py.

def tools::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 146 of file utils.py.

def tools::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 205 of file utils.py.

def tools::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 264 of file utils.py.

def tools::utils::intelhex_offset (   filename,
  offset 
)
Load a hex or bin file at a particular offset

Definition at line 520 of file utils.py.

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

Positional arguments:
command - the command to check

Definition at line 121 of file utils.py.

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

Positional arguments:
path - the executable

Definition at line 137 of file utils.py.

def tools::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 353 of file utils.py.

def tools::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 165 of file utils.py.

def tools::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 499 of file utils.py.

def tools::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 226 of file utils.py.

def tools::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 75 of file utils.py.

def tools::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 109 of file utils.py.

def tools::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 253 of file utils.py.