Skip to content

Instantly share code, notes, and snippets.

@h4ndzdatm0ld
h4ndzdatm0ld / saveflle
Created May 18, 2020 23:49
Save contents to file
def saveFile(filename, contents):
''' Save the contents to a file in the PWD.
'''
try:
f = open(filename, 'w+')
f.write(contents)
f.close()
except Exception as e:
print(e)
@h4ndzdatm0ld
h4ndzdatm0ld / netconf
Last active May 18, 2020 23:48
NETCONF template
def netconfconn(nodeip,ncusername,ncpassword):
conn = manager.connect(host=nodeip,
port=830,
username=ncusername,
password=ncpassword,
hostkey_verify=False,
device_params={'name':'alu'})
return conn
def createFolder(directory):
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print('Error: Creating directory. ' + directory)
@h4ndzdatm0ld
h4ndzdatm0ld / globfindfile
Last active November 17, 2020 05:59
globfindfile #glob,file,find
def globfindfile(regex):
''' This function will simply locate a file in the DIR by passing the directory/regex value (ie:(*.log))
The returned value by calling the function is the file.
'''
try:
if len(glob.glob(regex)) == 0:
sys.exit(f"No {regex} file found.")
else:
for file in glob.glob(regex):
if len(glob.glob(regex)) > 1: