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 Natural Sort (Alphanumeric Sort)

generic-sorting

Natural sort order is an ordering of strings in alphabetical order, except that multi-digit numbers are ordered as a single character. Natural sort order has been promoted as being more human-friendly (“natural”) than the machine-oriented pure alphabetical order.

def atoi(text):
    return int(text) if text.isdigit() else text

def natural_keys(text):
    '''
    alist.sort(key=natural_keys) sorts in human order
    http://nedbatchelder.com/blog/200712/human_sorting.html
    '''
    return [ atoi(c) for c in re.split('(\d+)', text) ]

# MAIN
alist.sort(key=natural_keys)

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.

Persistent Header/ Sticky Header/Stick to Scroll Web (IE/Chrome/Firefox)

I was searching the internet on how to code a sticky header using javascript and found so many articles and multiple ways to achieve it but most of them didn’t work on IE or some of them were too complicated to understand for a person like me who has little know how of the Javascript. So after searching for hours I found the article below which was simple and easy to understand furthermore it was working on IE .

 

“Many must’ve seen this automatic-header-scroll-stick feature. Where a normal looking header suddenly sticks to the page when the page is scrolled.

Gmail to recently introduced such a “auto-sticking-interaction-header”. I thought I should give a simple explanation about it.”

<!DOCTYPE html>
<html> 
<head>
  <meta name="generator" content= "HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
  <title>Auto Scroll Lock Header with jQuery</title> 
  <script src= "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"> </script> 
  <style type="text/css">
    table { 
      background: black;
      color: white;
    } 
    body, td {
      font: 13px sans-serif;
    }
    #stickyheader {
      width: 100%;
      height: 10px; 
    } 
    #stickyalias { 
      display: none; 
      height: 10px;
    }
    #unstickyheader {
      margin-bottom: 15px;
    }
    #othercontent { 
      margin-top: 20px;
    } 
  </style> 
</head> .... ... .. .

 [Read More: Article by Ruturaj]

How to Create a Custom Theme for Your WordPress Blog with Minimal Coding Required

One of the best article I found to start the wordpress.

You want to start your own blog but you don’t want to look tacky by using an existing design. Creating your own theme can be daunting, but with some assistance you can have a unique design for your blog in no time. This post will help you put it all together using WordPress, the most popular (and free) blogging software available. P

How to Create a Custom Theme for Your WordPress Blog with Minimal Coding Required

Creating a WordPress theme can take quite a bit of work when you’re starting from scratch because you have to put together quite a bit of PHP code (the programming language WordPress uses) before you can even get to creating the look and feel of your site. We’re going to save you the trouble by providing those files pre-made for you, plus a skeletal structure of the CSS you’re going to need to make your WordPress site look the way you want. The PHP code is based upon the work of Ian Stewart, but has been updated for WordPress 3.3.1. If you’re ready to get started, here’s what you’ll need:

[Read More: Full article by Adam Dachis]