os

Index

Overview

os provides a platform-independent interface to operating system functionality.

Functions

def chdir

chdir(dir)

changes the current working directory to the named directory.

Arguments
nametypedescription
dirstringtarget dir

def command

command(command, shell=False, dir="", combined=False, env=[])

runs the command and returns its standard output. If the exit code it different to zero, an error is triggered.

Arguments
nametypedescription
shellboolif True execute the command inside of a shell.
dirstringworking directory of the command.
combinedboolif True returns combined standard output and standard error.
envlistspecifies the environment of the process, each value of the listshould follow the pattern “key=value”.

def getenv

getenv(key) dir

retrieves the value of the environment variable named by the key.

Arguments
nametypedescription
keystringname of the environment variable

def getwd

getwd() dir

returns a rooted path name corresponding to the current directory.

def mkdir

mkdir(name, perms=0o777)

creates a new directory with the specified name and permission bits (before umask).

Arguments
nametypedescription
namestringname of the folder to be created
permsintoptional, permission of the folder

def mkdir_all

mkdir_all(name, perms=0o777)

creates a new directory with the specified name and permission bits (before umask).

Arguments
nametypedescription
namestringname of the folder to be created
permsintoptional, permission of the folder

def read_file

read_file(filename) string

reads the file named by filename and returns the contents.

Arguments
nametypedescription
filenamestringname of the file to be written
datastringcontent to be witten to the file
permsintoptional, permission of the file

def remove

remove(name)

removes the named file or (empty) directory.

Arguments
nametypedescription
namestringname of the file or directory to be deleted

def remove_all

remove_all(path)

removes path and any children it contains. It removes everything it can but returns the first error it encounters.

Arguments
nametypedescription
namestringpath to be deleted

def rename

rename(oldpath, newpath)

renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories.

Arguments
nametypedescription
oldpathstringold path
newpathstringnew path

def setenv

setenv(key, value) dir

sets the value of the environment variable named by the key.

Arguments
nametypedescription
keystringname of the environment variable
valuestringvalue of the environment variable

def temp_dir

temp_dir()

returns the default directory to use for temporary files.

def write_file

write_file(filename, data, perms=0o644)

retrieves the value of the environment variable named by the key.

Arguments
nametypedescription
filenamestringname of the file to be written
datastringcontent to be witten to the file
permsintoptional, permission of the file