Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Python
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Python section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2013, 05:46 AM
Registered User
 
Join Date: May 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy create-reuse-modify

the code given in chapter 2 of ceate-modify-reuse in python book to compare snapshots is not working.....
its not comparing the snapshots and giving exception message can anyone help me?

the complete code is available in code resources section of this site

parameters are passed in snap1 and snap2
its giving exception mssg "Problems encountered accessing snapshot files!"
here is the code:
def compareSnapshots(snapfile1, snapfile2):

try:
pkl_file = open(snapfile1, 'rb')
dirs1 = pickle.load(pkl_file)
files1 = pickle.load(pkl_file)
pkl_file.close()

pk2_file = open(snapfile2, 'rb')
dirs2 = pickle.load(pk2_file)
files2 = pickle.load(pk2_file)
pk2_file.close()
except:
print "Problems encountered accessing snapshot files!"
raw_input("\n\nPress [Enter] to continue...")
return

result_dirs = list(difflib.unified_diff(dirs1, dirs2))
result_files = list(difflib.unified_diff(files1, files2))

added_dirs = []
removed_dirs = []
added_files = []
removed_files = []

for result in result_files:
if result.endswith("\n") == -1:
if result.startswith('+'):
resultadd = result.strip('+')
added_files.append(resultadd)
elif result.startswith('-'):
resultsubtract = result.strip('-')
removed_files.append(resultsubtract)

for result in result_dirs:
if result.endswith("\n") == -1:
if result.startswith('+'):
resultadd = result.strip('+')
added_dirs.append(resultadd)
elif result.startswith('-'):
resultsubtract = result.strip('-')
removed_dirs.append(resultsubtract)

print "\n\nAdded Directories:\n"
printList(added_dirs)
print "\n\nAdded Files:\n"
printList(added_files)
print "\n\nRemoved Directories:\n"
printList(removed_dirs)
print "\n\nRemoved Files:\n"
printList(removed_files)
raw_input("\n\nPress [Enter] to continue...")


 
Old September 23rd, 2013, 03:49 AM
Registered User
 
Join Date: Sep 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

I've just bumped into the same issue. Did you manage to debug it?

Actually, I don't get the exception, but the result is always empty as if the snapshot were identical, and I'm sure I added some directories and files and removed other before taking the second snapshot.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adobe AIR: Create-Modify-Reuse (978-0-470-18207-9) jaswanttak BOOK: Adobe AIR: Create - Modify - Reuse ISBN: 978-0-470-18207-9 3 April 16th, 2009 11:48 AM
modify create appointment wizard jeanhl BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 March 24th, 2008 03:37 AM
XSL: template reuse ramesh.kumarm XSLT 16 December 1st, 2006 06:27 AM
How to reuse my application ankur_bhargava2000 VB How-To 1 October 17th, 2005 12:49 PM
Reuse in ASP. rupen Classic ASP Basics 3 June 29th, 2005 10:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.