Monthly Archives: February 2007

Powered by Python: Easy File Finder

More often than not I dig into tens of gigas of files to search for one I vaguely remember. I had though I could have shortcuts to files I frequent according to keywords.

Here comes the solution implemented with Python. This script take a criterion substring and searching all file names, whenever one is matched,  a corresponding shortcut is created into a designated folder.

  1: from os import walk
  2: from os.path import join, getsize
  3: import datetime
  4: import sys
  5: import os
  6: import re
  7: import win32com.client
  8: 
  9: def CreateShortcut(WhereSrc, WhereShortcut, ShortcutName):
 10:     """ This function creates a Windows shortcut for a directory or file,
 11:         WhereSrc:      path to a directory or file
 12:         WhereShortcut: path to the shortcut being placed
 13:         ShortcutName:  name of the Shortcut
 14:         Copyright @ Tomgee, 2007
 15:     """
 16: 
 17:     shell = win32com.client.Dispatch("WScript.Shell")
 18:     shortcut = shell.CreateShortCut(WhereShortcut + "\\" + ShortcutName + ".lnk")
 19:     shortcut.Targetpath = WhereSrc
 20:     shortcut.save()
 21: 
 22: def GoFind(path, substr, WhereShortcut):
 23:     """ this function take a valid directory path as input
 24:         walk through all files and directories in the passed in path, 
 25:         create a shortcut for each matched item.
 26:         path:           path to a directory or file
 27:         WhereShortcut:  path to the shortcut being placed
 28:         substr:         criteria string to match
 29:         Copyright @ Tomgee, 2007
 30:     """
 31: 
 32:     logfile = WhereShortcut + r'\log.txt'
 33:     print "Going through %s to find \'%s\'(case insensitive), \nsubdirectory included..."%(path, substr)
 34:     print "a log will be saved to %s"%logfile
 35:     f = open(logfile, 'a') # open a log file
 36:     sys.stdout = f   # un-comment this line out if the output to a file is preferred 
 37: 
 38:     now = datetime.datetime.now()
 39:     print "\n***********************************************"
 40:     print "Timestamp: %s"%now.strftime("%y-%m-%d, %H:%M:%S")
 41: 
 42:     totalCount = 0
 43:     substr_upper = substr.upper()
 44:     for root,dirs, files in walk(path):
 45:         for file in files:
 46:             if substr_upper in file.upper():
 47:                 fullpath = join(root,file)
 48:                 CreateShortcut(fullpath, WhereShortcut, file)
 49:                 print "File #%d: %s"%(totalCount,fullpath)
 50:             totalCount += 1
 51:     print "Totally %d files/directories under %s have been searched"%(totalCount, path)
 52:     print r'********* The End *********'
 53: 
 54: def main():
 55:     argCount            = len(sys.argv)
 56:     argCurDir           = os.getcwd()
 57:     argMatchStr         = ""
 58:     argShortcutsDir     = os.getcwd() + r'\shortcuts_for_'
 59: 
 60:     print "usage: %s [StringToMatch] [DirectoryToSearch, e.g. c:\] [DirectoryToPutShortcuts, e.g. c:\]" %os.path.basename(sys.argv[0])
 61:     if argCount > 1:
 62:         argMatchStr = sys.argv[1]
 63:     if argCount > 2:
 64:         argCurDir = sys.argv[2]
 65:     if argCount > 3:
 66:         argShortcutsDir = sys.argv[3]
 67: 
 68:     argFinalShortcutsDir = argShortcutsDir + argMatchStr
 69:     if not os.path.lexists(argFinalShortcutsDir):
 70:         os.mkdir(argFinalShortcutsDir)
 71:     GoFind(argCurDir, argMatchStr, argFinalShortcutsDir)
 72: if __name__ == '__main__': main()
 73: 
 74: 

Powered by Python: How to create Windows Shortcuts

import sys
import win32com.client

def CreateShortcut(WhereSrc, WhereShortcut, ShortcutName):
    """ This function creates a Windows shortcut for a directory or file,
        WhereSrc:      path to a directory or file
        WhereShortcut: path to the shortcut being placed
        ShortcutName:  name of the Shortcut
        Copyright @ Tomgee, 2007
    """

    shell = win32com.client.Dispatch("WScript.Shell")
    shortcut = shell.CreateShortCut(WhereShortcut + "\\" + ShortcutName + ".lnk")
    shortcut.Targetpath = WhereSrc
    shortcut.save()

Powered by Python: find files whose name contain a criteria string

from os import walk
from os.path import join, getsize
import datetime
import sys
import os
import re

def parse(path, substr="boost"):
    """ this function take a valid directory path as input
    walk through all files and directories and output all 
    matches into log.txt
    """

    logfile = path + r'\log.txt'
    print "Going through %s to find \'%s\'(case insensitive), \nsubdirectory included..."%(path, substr)
    print "a log will be saved to %s"%logfile
    f = open(logfile, 'a') # open a log file
    sys.stdout = f   # un-comment this line out if the output to a file is preferred 

    now = datetime.datetime.now()
    print "\n***********************************************"
    print "\nTimestamp: %s"%now.strftime("%y-%m-%d, %H:%M:%S")

    totalCount = 0
    substr_upper = substr.upper()
    for root,dirs, files in walk(path):
        for file in files:
            if substr_upper in file.upper():
                fullpath = join(root,file)
                print "File #%d: %s"%(totalCount,fullpath)
            #print root, "|", dirs, "|",files
            totalCount += 1
    print "Totally %d files/directories under %s have been searched"%(totalCount, path)
    print r'********* The End *********'

def main():
    from timeit import Timer
    if not len(sys.argv)== 2:
        print "usage: %s [directory, e.g. c:\]" %os.path.basename(sys.argv[0])
        parse(os.getcwd())
        #parse(os.curdir())        
        #raw_input('press <Enter> to continue...')    
    else:
        parse(sys.argv[1])
        #t = Timer("parse(sys.argv[1])", "from __main__ import parse")
        #t.repeat(3, 1000)    #.timeit()    

if __name__ == '__main__': main()

Stages of Software Development

by Christopher Diggins

 

Summary
What specifically are the phases of software development? I was taught there were about 4 or 5, but I believe I have identified a few more.


I was taught (back in ’94 by my software engineering professor) that the stages of software development were something like (my memory is hazy, so I am not probably giving her full justice):

  • gather requirements
  • design
  • implementation
  • debugging
  • testing

I believe that it is important to consider a more fine-grained and less linear view of the stages of software development. I consider the following to be important interleaved phases for the development of most non-trivial commercial software:

  • scheduling – Self explanatory.
  • research – Learning more about the problems the software attempts to solve, and what the competing software does.
  • technology selection – Choosing what tools, languages, and technologies to use to build and develop the software.
  • reuse – Identifying code libraries and tools internally and externally that can be leveraged
  • prototyping – An important step which is often overlooked (often-times the first version is really a prototype).
  • code documentation
  • product documentation
  • refactoring – Change in the code to changes in implementation design.
  • extending – This refers to when more features are added during development, after prototyping, or after a release
  • revising – Related to refactoring, this refers to when the product requirement are significantly changed in some-way
  • internationalization – It is is usually the case the software will be released in different locales with different languages and cultural conventions.
  • optimizing – It is rare that software doesn’t have some areas where better performance could significantly improve the product.
  • static analysis – Static analysis tools are an important part of detecting defects
  • reviewing code – Code reviews are an important supplement to testing
  • releasing – Getting the internal versions to various teams, and external versions to customers in a smooth and timely manner
  • recycling code – The code in a successful project will almost invariable be reused in some other project.
  • porting – Porting software to new operating systems and platforms is almost always inevitable in a successful product
  • support – Customer support is easily overlooked, but when taken into consideration will affect design decisions, and profitability.

By being aware of, and giving proper consideration to, these stages of software development I believe software projects increase their chances of success.