API Documentation

viki.fabric.helpers

viki.fabric.helpers.run_and_get_stdout(cmdString, hostString=None, useSudo=False)[source]

Runs a command and grabs its output from standard output, without all the Fabric associated stuff and other crap (hopefully).

Args:

cmdString(str): Command to run

hostString(str, optional): This should be passed the value of
env.host_string
useSudo(bool, optional): If True, sudo will be used instead of run
to execute the command
Returns:
list of str: List of strings from running the command
>>> run_and_get_stdout("ls")
["LICENSE", "README.md", "setup.py"]
viki.fabric.helpers.get_home_dir()[source]

Returns the home directory for the current user of a given server.

Returns:
str: the path to the home directory of the current host, or the string
“$HOME”
>>> get_home_dir()
"/home/ubuntu"
viki.fabric.helpers.download_remote_file_to_tempfile(remoteFileName)[source]

Downloads a file from a server to a tempfile.NamedTemporaryFile.

NOTE: This function calls the close method on the NamedTemporaryFile.

NOTE: The caller is reponsible for deleting the NamedTemporaryFile.

Args:
remoteFileName(str): name of the file on the server
Returns:
str: name of the temporary file whose contents is the same as the file on
the server
>>> downloadedFileName = download_remote_file_to_tempfile(
      "/home/ubuntu/a/search.rb"
    )
>>> with open(downloadedFileName, "r") as f:
      # do some processing here...
>>> os.unlink(downloadedFileName) # delete the file
viki.fabric.helpers.copy_file_to_server_if_not_exists(localFileName, serverFileName)[source]

Copies a file to the server if it does not exist there.

Args:

localFileName(str): local path of the file to copy to the server

serverFileName(str): path on the server to copy to

>>> copy_file_to_server_if_not_exists("helpers.py",
      os.path.join("my-repo", "helpers.py")
    )
viki.fabric.helpers.is_dir(path)[source]

Checks if a given path on the server is a directory.

Args:
path(str): path we wish to check
Returns:
bool: True if the given path on the server is a directory, False otherwise
>>> is_dir("/home/ubuntu")
True
viki.fabric.helpers.update_package_manager_package_lists()[source]

Updates the package list of the package manager (currently assumed to be apt-get)

>>> update_package_manage_package_lists()
viki.fabric.helpers.install_software_using_package_manager(softwareList)[source]

Installs a list of software using the system’s package manager if they have not been installed. Currently this assumes apt-get to be the package manager.

Args:
softwareList(list of str): list of software to install
>>> install_software_using_package_manager(
      ["vim", "openjdk-6-jdk", "unzip"]
    )
viki.fabric.helpers.is_installed_using_package_manager(software)[source]

Determines if a given software is installed on the system by its package manager (currently assumed to be apt-get).

Args:
software(str): The name of the software
Return:
bool: Returns True if the software is installed on the system using the
package manager, False otherwise
>>> is_installed_using_package_manager("python")
True
viki.fabric.helpers.setup_vundle(homeDir=None)[source]

Clones the Vundle vim plugin (https://github.com/gmarik/Vundle.vim) to the server (if it hasn’t been cloned), pulls updates, checkout v0.10.2, and installs vim plugins managed by Vundle.

Args:
homeDir(str, optional): home directory for the server. If not supplied or if
None is supplied, the return value of the get_home_dir function is used
>>> setup-vundle()

viki.fabric.git

viki.fabric.git.initialize(yamlConfigFile)[source]

Initializes globals in this module. This function should be called before using any public functions defined in this module.

Args:
yamlConfigFile(str): path to the YAML configuration file to read the
configuration from.
>>> initialize("fabric_git.yaml")
viki.fabric.git.is_dir_under_git_control(dirName)[source]

Determines if a directory on a server is under Git control.

Args:
dirName(str): directory name on the server for which we wish to determine
whether it’s under Git control
Returns:
bool: True if the directory on the server is under Git control, False
otherwise.
>>> is_dir_under_git_control("/home/ubuntu/viki-fabric-helpers")
True
viki.fabric.git.setup_server_for_git_clone()[source]

Fabric task that sets up the ssh keys and a wrapper script for GIT_SSH to allow cloning of private Github repositories.

Args:
homeDir(str, optional): home directory for the server. If not supplied or if
None is supplied, the return value of the fabric_helpers.get_home_dir function is used

For a Python Fabric script that imports the viki.fabric.git module using:

import viki.fabric.git

we can use this Fabric task from the command line, like so:

fab -H host1,host2,host3 viki.fabric.git.setup_server_for_git_clone

Alternatively, for a Python Fabric script that imports the viki.fabric.git module using:

import viki.fabric.git as fabric_git

we can use this Fabric task from the command like, like so:

fab -H host1,host2,host3 fabric_git.setup_server_for_git_clone

This function can also be called as a normal function (hopefully from within another Fabric task).

viki.fabric.git.is_fabtask_setup_server_for_git_clone_run(homeDir=None, printWarnings=True)[source]

Determines if the setup_server_for_git_clone Fabric task has been run.

This task checks for the existence of some files on the server to determine whether the setup_server_for_git_clone task has been run.

Args:
homeDir(str, optional): home directory for the server. If not supplied or if
None is supplied, the return value of the fabric_helpers.get_home_dir function is used
printWarnings(boolean): true if the setup_server_for_git_clone task has
been run, false otherwise.
Returns:
bool: True if the setup_server_for_git_clone Fabric task has been run for
the current server, False otherwise.
>>> is_fabtask_setup_server_for_git_clone_run()
False # along with some other output before this return value
viki.fabric.git.get_git_ssh_script_path(homeDir=None)[source]

Returns the path to the git ssh script

Args:
homeDir(str, optional): home directory for the server. If not supplied or if
None is supplied, the return value of the fabric_helpers.get_home_dir function is used
Returns:
str: the path to the git ssh script
>>> get_git_ssh_script_path()
"/home/ubuntu/git_ssh_wrap.sh"

Table Of Contents

Related Topics

This Page

Fork me on Github