2012年9月27日 星期四

[Python]Extract the difference files from two directory comparison





import filecmp
import os, sys
# bash : find . -type f // to recursively file all of file only in directory
def diffExtract(basedir, diffdir):
# Determine the items that exist in both directories
d1_contents=set([])
d2_contents=set([])
for root, subFolders, files in os.walk(basedir):
   for file in files:
subdir=root.replace(basedir, '') # just keep the common subdir path
d1_contents.add(os.path.join(subdir,file))
# print 'Dir1Files:', d1_contents
for root2, subFolders2, files2 in os.walk(diffdir):
   for file in files2:
subdir2=root2.replace(diffdir, '')
d2_contents.add(os.path.join(subdir2,file))
# print 'Dir2files:', d2_contents

common = list(d1_contents & d2_contents) # get the common file by join the Set
'''
common_files = [ f
       for f in common
       if os.path.isfile(os.path.join("~/build/QCT2050", f))
       ]
for f in common :
 ff=os.path.join("~/build/QCT2050", f)
 print "JoinPath:", ff
 if os.path.isfile(ff) :
   common_files.append(ff)

print 'Common files:', common_files
'''
print "removing the common file from ", diffdir
delcount=0
for f in common :
 ff1=basedir + f
 ff2=diffdir + f
 if (os.path.isfile(ff1) and os.path.isfile(ff2) and filecmp.cmp(ff1, ff2, shallow=False)) or os.path.islink(ff2) : #(os.path.isfile(ff)) :
   #common_files.append(ff)
   sys.stdout.write(".")
   sys.stdout.flush()
   os.remove(ff2)
   delcount += 1
print '\n%d common files are deleted from directory, %s.' % (delcount, diffdir)
return

# Compare the directories
#match, mismatch, errors = filecmp.cmpfiles(basedir,
#                                           diffdir,
#                                           common)
#print 'Match:', match
#print 'Mismatch:', mismatch
#print 'Errors:', errors

# ===========================================
def listFileRecursive(dir):
  # Determine the items that exist in both directories
  for root, subFolders, files in os.walk(basedir):
    for file in files:
print (os.path.join(root,file))

def mkfile(filename, body=None):
    with open(filename, 'w') as f:
        f.write(body or filename)
    return

def make_example_dir(top):
    if not os.path.exists(top):
        os.mkdir(top)
    curdir = os.getcwd()
    os.chdir(top)

    os.mkdir('dir1')
    os.mkdir('dir2')

    mkfile('dir1/file_only_in_dir1.txt')
    mkfile('dir2/file_only_in_dir2.txt')

    os.mkdir('dir1/dir_only_in_dir1')
    os.mkdir('dir2/dir_only_in_dir2')

    os.mkdir('dir1/common_dir')
    os.mkdir('dir2/common_dir')

    mkfile('dir1/common_file', 'this file is the same.txt')
    mkfile('dir2/common_file', 'this file is the same.txt')

    mkfile('dir1/not_the_same.txt')
    mkfile('dir2/not_the_same.txt')

    mkfile('dir1/file_in_dir1', 'This is a file in dir1.txt')
    os.mkdir('dir2/file_in_dir1')
   
    os.chdir(curdir)
    return

if __name__ == '__main__':
    #os.chdir(os.path.dirname(__file__) or os.getcwd())
    #make_example_dir('example')
    #make_example_dir('example/dir1/common_dir')
    #make_example_dir('example/dir2/common_dir')
    print ''
    print 'Usage : %s basedir diffdir' % (sys.argv[0])
    basedir=sys.argv[1]  # The common part directory
    diffdir=sys.argv[2]  # The different part directory
    print 'This program is to compare the content of base directory, and variant directory, then delete all of common and same content file from variant directory.'
    print 'Warning : This program will really make change on the variant directory, %s.' % (diffdir)
    print 'Please make sure that is what you want.'
    raw_input("Press Enter to continue ...");
    diffExtract(basedir, diffdir)

2012年8月6日 星期一

RTC Concept

Concept
Repozitory : The repository includes auditable item types, which maintain a history of item creation and subsequent modifications for audit purposes. The audit trail includes a record of past states of the item, the user who saved the item, and the time of the change. For item types that do not require audit history, the repository retains only the latest state of the item.
Project Area : The project area is a system representation of a software project. The project area defines the project deliverables, team structure, process, and schedule. A project area is stored as a top-level or root item in a repository. A project area references project artifacts and stores the relationships between these artifacts.

2012年4月30日 星期一

Python - a study note

Reference : http://www.rexx.com/~dkuhlman/python_book_01.html
  • Naming
    • Allowed characters in a name: a-z A-Z 0-9 underscore, and must begin with a letter or underscore.
    • Names and identifiers are case sensitive.
    • Identifiers can be of unlimited length.Special names, customizing, etc. -- Usually begin and end in double underscores.
    • Special name classes -- Single and double underscores.
      • Leading double underscores -- Name mangling for method names.
      • Leading single underscore -- Suggests a "private" method name in a class. Not imported by "from module import *".
      • Trailing single underscore -- Sometimes used to avoid a conflict with a keyword, for example, class_.
    • Naming conventions -- Not rigid, but here is one set of recommendations:
      • Modules and packages -- all lower case.
      • Globals and constants -- Upper case.
      • Class names -- Bumpy caps with initial upper.
      • Method and function names -- All lower case with words separated by underscores.
      • Local variables -- Lower case (possibly with underscore between words) or bumpy caps with initial lower or your choice.
  • No declaration or data type definition is needed/used.
  • Block
    • Python represents block structure and nested block structure with indentation, not with begin and end brackets
    • The statements which go together must have the same indentation. Each such set of statements is called a block.
    • The empty block -- Use the pass no-op statement.
  • DocStrings : A doc string is a quoted string at the beginning of a module, function, class, or method.We can use triple-quoting to create doc strings that span multiple lines.
    • Doc strings can be viewed with several tools, e.g. help(),obj.__doc__, and, in IPython, a question mark (?) after a name will produce help.
  • Statement
    • while running:
          guess = int(raw_input('Enter an integer : '))
          if guess == number:
             print 'Congratulations, you guessed it.'
             running = False # this causes the while loop to stop
          elif guess < number:
             print 'No, it is a little higher than that.'
             continue

          else:
             print 'No, it is a little lower than that.'
             break

      else:
          print 'The while loop is over.'
      # Do anything else you want to do here
      print 'Done'
    • for i in range(1, 5):
         print i
      else:
         print 'The for loop is over'

Python Development with Eclipse

  1. extract Eclipse : eclipse-java-indigo-win32_32bit.zip
  2. Install PyDev plugin for Eclipse
    1. Help/Install New Software
    2. Add Repository : PyDev - http://pydev.org/updates
    3. select [PyDev] => [Next]/[Next]/Accept license/[Finish] => select trust certificate/[OK]
    4. Restart Eclipse
  3. Configuration PyDev
    1. Window/Preferences
    2. Select PyDev/Interpreter - Python => press [Auto Config] (ps. precondition : python installed) => [OK]
    1. Install UML modeling for phthon Feature (Using TextUML Toolkit + Acceleo)
      1. Install TextUML Toolkit
        1. Help/Install New Software
        2. Add Repository : TextUML Toolkit - http://abstratt.com/update/
        3. select All => [Next]/[Next]/Accept license/[Finish]
      2. Install Acceleo code generator – http://acceleo.org/update/
        1. Help/Install New Software
        2. Add Repository : Acceleo code generator – http://acceleo.org/update/
        3. select Acceleo => [Next]/[Next]/Accept license/[Finish]
      3. Install Acceleo code generation modules
          1. Help/Install New Software
          2. Add Repository : Acceleo code generation modules - http://acceleo.org/modules/update
          3. select Acceleo Modules Experimental/Ecore to Python code generator => [Next]/[Next]/Accept license/[Finish]
    2. Use PyDev to develop python
      1. Window/Open Perspective/Other => select PyDev/[OK]
      2. File/New/PyDev Project
      3. Project name : scm_build, Grammer version : 2.6 => [Finish]
    3. Create Python UML
      1. New/Other => Acceleo/Module Luncher [Next] Encore to Python => [Next]
      2. Encore Model : /scm_build/module/scm_build.ecore
        Output folder : /scm_build/out
        Error Log file : /scm_build/error.log

    [Solved]Can't connect BoxNet Dav network drive in Windows XP

    1. Start up WebClient service in Windows Service
    2. connect net drive by file://www.box.net/dav

    2012年3月8日 星期四

    Replace framework.jar on Android Emulator



    1. Start up Emulator
      $ cd {ANDROID SDK}/tools
      $ ./emulator -avd {AVD_NAME}
    2. Use adb shell to set rw access right on /system
      $ ./adb shell
      # mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
      # cd /system/bin
      # cat sh > su
      # chmod 4755 su
      # exit
    3. upload framework.jar to target directory
      $ ./adb push
     {MYDONUT_OUT_PATH}/target/product/generic/system/framework/framework.jar /system/framework
    4. restart Emulator
      $ ./adb shell
      # stop
      # start



    2012年1月4日 星期三

    RTC Post Installation Setup/Configuration

    1. Run Setup Wizardhttps://[fully qualified hostname]:9443/jts/setup
      1. Configure Public URI
      2. Configure Database
        1. Configure Database Vendor and Connection Type
          Database Vendor: iDerby
          Connection Type: JDBC
      3. Enable E-mail Notification
      4. Register Applications

    Application InstanceApplication TypeDiscovery URLFunctional User ID /rmRequirements Managementhttps:// hostname:9443/rm/scrrm_user /ccmChange and Configuration Managementhttps:// hostname:9443/ccm/scrccm_user /qmQuality Managementhttps:// hostname:9443/qm/scrqm_user /admin Lifecycle Project Administrationhttps:// hostname:9443/admin/scrlpa_user
    1. Setup User Registry
      Administartor : scm/scmr1scm
    2. Configure Data Warehouse
      data collection jobs User : dm_scm/scmr1scm