[Pypt-offline-general] SF.net SVN: pypt-offline: [156] trunk/pypt_core.py
Status: Beta
Brought to you by:
riteshsarraf
|
From: <rit...@us...> - 2007-07-27 19:03:48
|
Revision: 156
http://pypt-offline.svn.sourceforge.net/pypt-offline/?rev=156&view=rev
Author: riteshsarraf
Date: 2007-07-27 12:03:50 -0700 (Fri, 27 Jul 2007)
Log Message:
-----------
* Enhanced socket handling
* Increased the socket timeout value to 30 secs
* Handle socket timeout exceptions when fetching data from the network
* Made WConio usage conditional because it is used primarily on Windows when the modules is available.
* Fixed the logic for when to download bug reports and how to handle them.
Modified Paths:
--------------
trunk/pypt_core.py
Modified: trunk/pypt_core.py
===================================================================
--- trunk/pypt_core.py 2007-07-27 13:09:25 UTC (rev 155)
+++ trunk/pypt_core.py 2007-07-27 19:03:50 UTC (rev 156)
@@ -10,12 +10,12 @@
import signal
import optparse
import array
+import socket
from array import array
-from socket import setdefaulttimeout
#INFO: Set the default timeout to 15 seconds for the packages that are being downloaded.
-setdefaulttimeout(15)
+socket.setdefaulttimeout(30)
#INFO: They aren't on Windows
@@ -178,7 +178,9 @@
sys.stderr.write(msg)
sys.stderr.flush()
- WConio.textcolor(15) #Once the error is displayed, change back to the normal color
+
+ if self.color:
+ WConio.textcolor(15) #Once the error is displayed, change back to the normal color
if self.lock:
self.DispLock.release()
@@ -194,7 +196,9 @@
sys.stdout.write(msg)
sys.stdout.flush()
- WConio.textcolor(15) #Once the error is displayed, change back to the normal color
+
+ if self.color:
+ WConio.textcolor(15) #Once the error is displayed, change back to the normal color
if self.lock:
self.DispLock.release()
@@ -213,7 +217,8 @@
sys.stdout.write(msg)
sys.stdout.flush()
- WConio.textcolor(15) #Once the error is displayed, change back to the normal color
+ if self.color:
+ WConio.textcolor(15) #Once the error is displayed, change back to the normal color
if self.lock:
self.DispLock.release()
@@ -350,7 +355,10 @@
except IOError:
sys.exit(1)
- (num_of_bugs, header, self.bugs_list) = debianbts.get_reports(PackageName)
+ try:
+ (num_of_bugs, header, self.bugs_list) = debianbts.get_reports(PackageName)
+ except socket.timeout:
+ return False
if num_of_bugs:
for x in self.bugs_list:
@@ -367,7 +375,10 @@
for x in sub_bugs_list:
break_bugs = x.split(':')
bug_num = string.lstrip(break_bugs[0], '#')
- data = debianbts.get_report(bug_num, followups=True)
+ try:
+ data = debianbts.get_report(bug_num, followups=True)
+ except socket.timeout:
+ return False
if Filename == None:
self.fileName = PackageName + "." + bug_num
file_handle = open(self.fileName, 'w')
@@ -499,6 +510,9 @@
if hasattr(e, 'code') and hasattr(e, 'reason'):
errfunc(e.code, e.reason, file)
+ except socket.timeout:
+ errfunc(101010, "Socket timeout.", file)
+
def copy_first_match(cache_dir, filename, dest_dir, checksum): # aka new_walk_tree_copy()
'''Walks into "reposiotry" looking for "filename".
If found, copies it to "dest_dir" but first verifies their md5 "checksum".'''
@@ -564,11 +578,13 @@
This function does the job of behaving accordingly
as per the error codes.
'''
- error_codes = [-3, 13, 504, 404, 10060, 104]
+ error_codes = [-3, 13, 504, 404, 10060, 104, 101010]
# 104, 'Connection reset by peer'
# 504 is for gateway timeout
# 404 is for URL error. Page not found.
# 10060 is for Operation Time out. There can be multiple reasons for this timeout
+ # 101010 - Dummy error code for socket timeouts. FIXME: Find the
+ # correct socket timeout error code
#TODO: Find out what these error codes are for
# and better document them the next time you find it out.
@@ -766,11 +782,16 @@
if ArgumentOptions.zip_it:
FetcherInstance.compress_the_file(ArgumentOptions.zip_upgrade_file, file)
+ log.verbose("%s added to archive %s.\n" % (file, ArgumentOptions.zip_upgrade_file) )
os.unlink(os.path.join(download_path, file))
+ else:
+ #Copy the bug report to the target download_path folder
+ if bug_fetched == 1:
+ for x in os.listdir(os.curdir()):
+ if x.startswith(PackageName):
+ shutil.move(x, download_path)
+ log.verbose("Moved %s file to %s folder.\n" % (x, download_path) )
- if bug_fetched:
- if FetchBugReportsDebian.AddToArchive(ArgumentOptions.zip_upgrade_file):
- log.verbose("Archived bug reports for package %s to archive %s\n" % (PackageName, ArgumentOptions.zip_upgrade_file) )
else:
raise FetchDataKeyError
@@ -895,25 +916,35 @@
#INFO: You're and idiot.
# You should NOT disable md5checksum for any files
else:
- #INFO: If md5check is disabled, just copy it to the cache_dir
- try:
- shutil.copy(full_file_path, download_path)
- log.success("%s copied from local cache directory %s\n" % (file, cache_dir) )
- except shutil.Error:
- log.verbose("%s already available in dest_dir. Skipping copy!!!\n\n" % (file) )
-
if ArgumentOptions.deb_bugs:
+ bug_fetched = 0
if FetchBugReportsDebian.FetchBugsDebian(PackageName):
log.verbose("Fetched bug reports for package %s.\n" % (PackageName) )
-
- file = full_file_path.split("/")
- file = file[len(file) - 1]
- file = download_path + "/" + file
+ bug_fetched = 1
+
+ #FIXME: Don't know why this was really required. If this has no changes, delete it.
+ #file = full_file_path.split("/")
+ #file = file[len(file) - 1]
+ #file = download_path + "/" + file
if ArgumentOptions.zip_it:
if FetcherInstance.compress_the_file(ArgumentOptions.zip_upgrade_file, file) != True:
log.err("Couldn't archive %s to file %s\n" % (file, ArgumentOptions.zip_upgrade_file) )
sys.exit(1)
os.unlink(os.path.join(download_path, file) )
+ else:
+ # Since zip file option is not enabled let's copy the file to the target folder
+ try:
+ shutil.copy(full_file_path, download_path)
+ log.success("%s copied from local cache directory %s\n" % (file, cache_dir) )
+ except shutil.Error:
+ log.verbose("%s already available in dest_dir. Skipping copy!!!\n\n" % (file) )
+
+ # And also the bug reports
+ if bug_fetched == 1:
+ for x in os.listdir(os.curdir()):
+ if x.startswith(PackageName):
+ shutil.move(x, download_path)
+ log.verbose("Moved %s file to %s folder.\n" % (x, download_path) )
else:
#INFO: This block gets executed if the file is not found in local cache_dir or cache_dir is None
@@ -960,7 +991,8 @@
else:
#log.err("Couldn't find %s\n" % (PackageName) )
errlist.append(PackageName)
-
+ else:
+ raise FetchDataKeyError
# Create two Queues for the requests and responses
requestQueue = Queue.Queue()
responseQueue = Queue.Queue()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|