Simple python logging module wrapper

Simple python logging module wrapper that can be inherited to the class or can be used as a standalone. This logging wrapper supports logging level of INFO, ERROR and DEBUG with option to print to CONSOLE, FILE , BOTH and NONE.  git pull from mlogger repo.

Following is an example

# Inherited to Class
class tester(MLOGGER):
    def __init__(self):
        MLOGGER.__init__(self,'test',logtype='NONE', filename = 'mylogg.log')
    def testmethod(self):
        self.error('error test')
        self.debug('debug test')
        self.warn('warn test')
        self.info('info test')

t = tester()
t.testmethod()

# As Standalone
logger= MLOGGER('Test', level=INFO, logtype = 'CONSOLE', filename = 'mylog.log')
logger.debug('debug test')
logger.info('info test')
logger.warn('warn test')
logger.error('error test')

Python: How to create zip of files?

Download Code From Here

import zipfile
import time
import os

def create_zip(zip_filenames):
  zipped_name='ZipFile'+str(time.strftime("%m%d%Y_%H%M%S"))+'.zip'
  print "Creating ", zipped_name
  zf = zipfile.ZipFile(zipped_name, mode='w')

for filename in zip_filenames:
  try:
    print "Adding",filename,"in",zipped_name
    zf.write(filename)
  except:
    ":::ERROR::: Unable to add file to zipped file"
     print "Created Zipped File",zipped_name 
     zf.close()

def remove_files(remove_filesnames):
  for filename in remove_filesnames:
    print "Removing", filename
    os.remove(filename)


if __name__=="__main__":

  filenames= ['syspreset001','syspreset0161.prst','zip']
  create_zip(filenames)
  remove_files(filenames)

Python: How to download file using FTP?

Download the following script from Here.

####
#Download File with FTP.
#Download_System requires two variables HOST & directory & filename
####

import ftplib
import sys

#Host and Gets the Filename of the Preset
def Download_System(HOST,directory,filename):
  try:
    filename_get=filename
    directory_get=directory
    ftp_download=ftplib.FTP(HOST) #opens Ftp Connection to the HOST
    ftp_download.login( "root", "root") #username, password
    ftp_download.cwd(directory_get) #Change Directory to file directory
    localfile=open(filename_get,'wb') #Open Localfile to write
    ftp_download.retrbinary("RETR " + filename_get, localfile.write) #Get the Filname in Binary
  except Exception as e:
    print ":::ERROR:::: " +str(e)

if __name__=="__main__":
  HOST='Host'
  Filename='Filename'
  Directory='Change Directory Here'
  Download_System(HOST,Directory,Filename)

Learning Python GUI using Tkinter

As I wanted to learn the python GUI,
I searched on internet and found these very nice tutorials on how to built GUI using Tkinter library of python. There are few more GUI libraries available on the internet as you may be aware such as wxpython, but I found Tkinter suitable for my needs and easy to work with. I started learning from UsingPython , it also has a good basic python tutorials if you want to have a refresher course.

pythoncourse

The other one was the Python Course which also has some really nice examples and a bit more than using python but both are good and you can start from either one.

Following are library references which are handy to know what things you can change using arguments.