[Pypt-offline-general] SF.net SVN: pypt-offline: [186] trunk/pypt_core.py
Status: Beta
Brought to you by:
riteshsarraf
|
From: <rit...@us...> - 2007-08-17 11:14:51
|
Revision: 186
http://pypt-offline.svn.sourceforge.net/pypt-offline/?rev=186&view=rev
Author: riteshsarraf
Date: 2007-08-17 04:14:50 -0700 (Fri, 17 Aug 2007)
Log Message:
-----------
C:\Eclipse\Workspace\pypt-offline>hg log -l 2 -v
changeset: 166:a0954cf2b81a
branch: trunk
tag: tip
user: Ritesh Raj Sarraf <rr...@re...>
date: Fri Aug 17 16:41:35 2007 +0530
files: pypt_core.py
description:
* Add option --test-windows to avoid the call of os.geteuid() on Windows.
changeset: 165:a4e7b8f2b038
branch: trunk
user: Ritesh Raj Sarraf <rr...@re...>
date: Fri Aug 17 16:33:03 2007 +0530
files: pypt_core.py
description:
* Put all imports at the top-level. This has already hurt much. Things are done for good. Folloow standard practices.
Modified Paths:
--------------
trunk/pypt_core.py
Modified: trunk/pypt_core.py
===================================================================
--- trunk/pypt_core.py 2007-08-13 20:51:03 UTC (rev 185)
+++ trunk/pypt_core.py 2007-08-17 11:14:50 UTC (rev 186)
@@ -31,12 +31,16 @@
import socket
import tempfile
-from array import array
+import zipfile
+import bz2
+import gzip
-#INFO: Set the default timeout to 15 seconds for the packages that are being downloaded.
-socket.setdefaulttimeout(30)
+import debianbts
+import pypt_magic
+from array import array
+
#INFO: They aren't on Windows
try:
from fcntl import ioctl
@@ -50,6 +54,10 @@
except ImportError:
WindowColor = False
+#INFO: Set the default timeout to 15 seconds for the packages that are being downloaded.
+socket.setdefaulttimeout(30)
+
+
'''This is the core module. It does the main job of downloading packages/update packages,\nfiguring out if the packages are in the local cache, handling exceptions and many more stuff'''
@@ -62,9 +70,6 @@
supported_platforms = ["Linux", "GNU/kFreeBSD", "GNU"]
apt_update_target_path = '/var/lib/apt/lists/'
apt_package_target_path = '/var/cache/apt/archives/'
-# Dummy paths while testing on Windows
-#apt_update_target_path = 'C:\\temp'
-#apt_package_target_path = 'C:\\temp'
pypt_bug_file_format = "__pypt__bug__report"
bugTypes = ["Resolved bugs", "Normal bugs", "Minor bugs", "Wishlist items", "FIXED"]
@@ -86,7 +91,6 @@
def md5_check(self, file, checksum):
data = open(file, 'rb')
- #local = md5_string(data)
if checksum == self.md5_string(data):
return True
return False
@@ -242,10 +246,6 @@
elif os.name in ['nt', 'dos']:
self.platform = None
- #try:
- # import WConio
- #except ImportError:
- # self.platform = None
if WindowColor is True:
self.platform = 'microsoft'
@@ -346,11 +346,6 @@
'''Condenses all the files into one single file for easy transfer'''
try:
- import zipfile
- except ImportError:
- return False
-
- try:
if self.lock:
self.ZipLock.acquire(True)
filename = zipfile.ZipFile(zip_file_name, "a")
@@ -374,10 +369,6 @@
if archive_type is 1:
- try:
- import bz2
- except ImportError:
- return False
try:
read_from = bz2.BZ2File(archive_file, 'r')
@@ -396,10 +387,6 @@
return True
elif archive_type is 2:
- try:
- import gzip
- except ImportError:
- return False
try:
read_from = gzip.GzipFile(archive_file, 'r')
@@ -419,10 +406,10 @@
elif archive_type is 3:
# FIXME: This looks odd. Where are we writing to a file ???
- #try:
- zip_file = zipfile.ZipFile(file, 'rb')
- #except:
- # return False
+ try:
+ zip_file = zipfile.ZipFile(file, 'rb')
+ except IOError:
+ return False
for filename in zip_file.namelist():
data = zip_file.read()
@@ -444,16 +431,9 @@
if self.lock:
Archiver.__init__(self, lock)
self.ArchiveFile = ArchiveFile
- #ArchiveFiles = Archiver(True)
- #import debianbts
def FetchBugsDebian(self, PackageName, Filename=None):
- try:
- import debianbts
- except ImportError:
- return False
-
if Filename != None:
try:
file_handle = open(Filename, 'a')
@@ -895,7 +875,6 @@
if FetcherInstance.compress_the_file(zip_update_file, file) != True:
log.verbose("%s added to archive %s.\n" % (file, zip_update_file) )
os.unlink(os.path.join(download_path, file) ) # Remove it because we don't need the file once it is zipped.
- #sys.exit(1)
pass
elif key == 'Upgrade':
@@ -1259,12 +1238,6 @@
archive = Archiver()
- try:
- import pypt_magic
- except ImportError:
- log.err("Error: Module pypt_magic not found.\n")
- sys.exit(1)
-
def display_options():
log.msg("(Y) Yes. Proceed with installation\n")
@@ -1308,12 +1281,6 @@
log.msg("%s file synced.\n" % (filename))
if path_type == 1:
-
- try:
- import zipfile
- except ImportError:
- log.err("Error: Module zipfile not found.\n")
- sys.exit(1)
file = zipfile.ZipFile(install_file_path, "r")
if bug_parse_required is True:
@@ -1562,6 +1529,7 @@
action="store", type="string", metavar="pypt-offline-upgrade.zip")
parser.add_option("", "--fetch-bug-reports", dest="deb_bugs",
help="Fetch bug reports from the BTS", action="store_true")
+ parser.add_option("", "--test-windows", dest="test_windows", help="This switch is used while doing testing on windows.", action="store_true")
#global options, args
(options, args) = parser.parse_args()
@@ -1692,14 +1660,19 @@
sys.exit(1)
if options.install_update:
- #INFO: Comment these lines to do testing on Windows machines too
- #try:
- # if os.geteuid() != 0:
- # log.err("\nYou need superuser privileges to execute this option\n")
- # sys.exit(1)
- #except AttributeError:
- # log.err("Are you really running the install command on a Debian box?\n")
- # sys.exit(1)
+ if options.test_windows:
+ # Dummy paths while testing on Windows
+ apt_update_target_path = 'C:\\temp'
+ apt_package_target_path = 'C:\\temp'
+ pass
+ else:
+ try:
+ if os.geteuid() != 0:
+ log.err("\nYou need superuser privileges to execute this option\n")
+ sys.exit(1)
+ except AttributeError:
+ log.err("Are you really running the install command on a Debian box?\n")
+ sys.exit(1)
if os.path.isfile(options.install_update) is True:
# Okay! We're a file. It should be a zip file
@@ -1712,14 +1685,20 @@
sys.exit(1)
if options.install_upgrade:
- #INFO: Comment these lines to do testing on Windows machines too
- #try:
- # if os.geteuid() != 0:
- # log.err("\nYou need superuser privileges to execute this option\n")
- # sys.exit(1)
- #except AttributeError:
- # log.err("Are you really running the install command on a Debian box?\n")
- # sys.exit(1)
+ if options.test_windows:
+ # Dummy paths while testing on Windows
+ apt_update_target_path = 'C:\\temp'
+ apt_package_target_path = 'C:\\temp'
+ pass
+ else:
+ try:
+ if os.geteuid() != 0:
+ log.err("\nYou need superuser privileges to execute this option\n")
+ sys.exit(1)
+ except AttributeError:
+ log.err("Are you really running the install command on a Debian box?\n")
+ sys.exit(1)
+
if os.path.isfile(options.install_upgrade) is True:
syncer(options.install_upgrade, apt_package_target_path, 1, bug_parse_required = True)
elif os.path.isdir(options.install_upgrade) is True:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|