[Biopython-dev] [Bug 2945] New: update_pdb: shutil.move needs to be indented; try block also?

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Wed Nov 4 13:52:18 EST 2009


http://bugzilla.open-bio.org/show_bug.cgi?id=2945

           Summary: update_pdb: shutil.move needs to be indented; try block
                    also?
           Product: Biopython
           Version: 1.52
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Main Distribution
        AssignedTo: biopython-dev at biopython.org
        ReportedBy: TallPaulInJax at yahoo.com


As written, shutil.move will only move the last file if there are any. If there
aren't any, it will raise an exception since old_file and new_file are not
initialized. Finally, any failure to move the file will also raise an exception
(I believe), so a try block should be in place:

Existing code:
        # move the obsolete files to a special folder
        for pdb_code in obsolete:
            if self.flat_tree:
                old_file = self.local_pdb + os.sep + 'pdb%s.ent'%(pdb_code)
                new_file = self.obsolete_pdb + os.sep + 'pdb%s.ent'%(pdb_code)
            else:
                old_file = self.local_pdb + os.sep + pdb_code[1:3] + os.sep +
'pdb%s.ent'%(pdb_code)
                new_file = self.obsolete_pdb + os.sep + pdb_code[1:3] + os.sep
+ 'pdb%s.ent'%(pdb_code)
        shutil.move(old_file, new_file)

shutil.move needs to be indented one column, and potentially a try/catch phrase
added:

        for pdb_code in obsolete:
            if self.flat_tree:
                old_file = self.local_pdb + os.sep + 'pdb%s.ent'%(pdb_code)
                new_file = self.obsolete_pdb + os.sep + 'pdb%s.ent'%(pdb_code)
            else:
                old_file = self.local_pdb + os.sep + pdb_code[1:3] + os.sep +
'pdb%s.ent'%(pdb_code)
                new_file = self.obsolete_pdb + os.sep + pdb_code[1:3] + os.sep
+ 'pdb%s.ent'%(pdb_code)
            try:
                shutil.move(old_file, new_file)
            except:
                warnings.warn("Unable to move from old file: \n%s\n to new
file: \n%s\n" % (old_file, new_file)
                              RuntimeWarning)


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


More information about the Biopython-dev mailing list