created new method printerr
modified: modules/utils.py
This commit is contained in:
parent
20ebbe21b8
commit
408a36d5a5
1 changed files with 20 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
@ -12,10 +13,27 @@ from fabric.operations import run, sudo
|
||||||
def printvar(name, value, exit=False):
|
def printvar(name, value, exit=False):
|
||||||
print "%s : %s" % (name, value)
|
print "%s : %s" % (name, value)
|
||||||
if exit:
|
if exit:
|
||||||
import sys
|
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
def printerr(message="", errcode=-2, exit=True):
|
||||||
|
""" prints error message and error code then exits
|
||||||
|
|
||||||
|
Keyword Arguments:
|
||||||
|
message -- error message
|
||||||
|
errcode -- the error code
|
||||||
|
exit -- if we do a sys.exit
|
||||||
|
"""
|
||||||
|
|
||||||
|
message = "Error\n\t{message}\n\tExiting with code: {errcode}\n".format(
|
||||||
|
message=message, errcode=errcode)
|
||||||
|
|
||||||
|
print
|
||||||
|
print message
|
||||||
|
print
|
||||||
|
sys.exit(errcode)
|
||||||
|
|
||||||
|
|
||||||
def loggify(module, func, prefix=""):
|
def loggify(module, func, prefix=""):
|
||||||
"""
|
"""
|
||||||
I'm tired of rewriting this logging code in every single function, so I
|
I'm tired of rewriting this logging code in every single function, so I
|
||||||
|
|
@ -350,7 +368,7 @@ def link_create(path_src, path_dst, debug=False):
|
||||||
else:
|
else:
|
||||||
msg_error = "something exists at dst - '%s' " \
|
msg_error = "something exists at dst - '%s' " \
|
||||||
"- and it's not a link\n kicking out".format(path_dst)
|
"- and it's not a link\n kicking out".format(path_dst)
|
||||||
import sys
|
|
||||||
sys.exit(msg_error)
|
sys.exit(msg_error)
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
|
|
@ -371,7 +389,6 @@ def prompt_continue(message="Do you want to continue? Y/n", default="Y"):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from fabric.operations import prompt
|
from fabric.operations import prompt
|
||||||
import sys
|
|
||||||
|
|
||||||
prompt_val = prompt(message)
|
prompt_val = prompt(message)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue