r80867 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80866‎ | r80867 | r80868 >
Date:16:57, 24 January 2011
Author:diederik
Status:deferred
Tags:
Comment:
Unzipping didn't work on Ubuntu, fixed that.
Modified paths:
  • /trunk/tools/editor_trends/utils/compression.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/utils/compression.py
@@ -13,7 +13,7 @@
1414 '''
1515
1616 __author__ = '''\n'''.join(['Diederik van Liere (dvanliere@gmail.com)', ])
17 -__author__email = 'dvanliere at gmail dot com'
 17+__email__ = 'dvanliere at gmail dot com'
1818 __date__ = '2010-11-27'
1919 __version__ = '0.1'
2020
@@ -24,13 +24,15 @@
2525
2626 import configuration
2727 settings = configuration.Settings()
28 -import utils
 28+import file_utils
2929 import exceptions
 30+import timer
 31+import log
3032
3133 class Compressor(object):
3234
3335 def __init__(self, location, file, output=None):
34 - self.extension = utils.determine_file_extension(file)
 36+ self.extension = file_utils.determine_file_extension(file)
3537 self.file = file
3638 self.location = location
3739 self.path = os.path.join(self.location, self.file)
@@ -60,7 +62,10 @@
6163 if self.program_installed == None:
6264 raise exceptions.CompressionNotSupportedError
6365
64 - args = {'7z': ['%s' % self.program_installed, 'a', '-scsUTF-8', '-t%s' % self.compression, '%s' % self.output, '%s' % self.input],
 66+ args = {'7z': ['%s' % self.program_installed, 'a', '-scsUTF-8',
 67+ '-t%s' % self.compression,
 68+ '%s' % self.output,
 69+ '%s' % self.input],
6570 }
6671
6772 commands = args.get(self.name, None)
@@ -84,11 +89,9 @@
8590
8691 print self.location
8792 print self.file
88 - if not utils.check_file_exists(self.location, self.file):
 93+ if not file_utils.check_file_exists(self.location, self.file):
8994 raise exceptions.FileNotFoundException(self.location, self.file)
9095
91 -
92 -
9396 args = {'7z': ['%s' % self.program_installed, 'e', '-y', '-o%s' % self.location, '%s' % self.path],
9497 'bunzip2': ['%s' % self.program_installed, '-k', '%s' % self.path],
9598 'zip': ['%s' % self.program_installed, '-o', '%s' % self.path],
@@ -96,7 +99,7 @@
97100 'tar': ['%s' % self.program_installed, '-xvf', '%s' % self.path]
98101 }
99102 commands = args.get(self.name, None)
100 - print commands
 103+ #print commands
101104 if commands != None:
102105 p = subprocess.call(commands)
103106 #p = subprocess.Popen(commands, shell=True).wait()
@@ -104,19 +107,6 @@
105108 raise exceptions.CompressionNotSupportedError
106109 return p
107110
108 -# if self.name == '7z':
109 -# p = subprocess.Popen(['%s' % tool.extract_installed, 'e', '-o%s' % location, '%s' % input], shell=True).wait()
110 -# elif tool_extract_installed.endswith('bunzip2'):
111 -# p = subprocess.Popen(['%s' % tool.extract_installed, '-k', '%s' % input], shell=True).wait()
112 -# elif tool.extract_installed.endswith('zip'):
113 -# p = subprocess.Popen(['%s' % tool.extract_installed, '-o', '%s' % input], shell=True).wait()
114 -# elif tool.extract_installed.endswith('gz'):
115 -# p = subprocess.Popen(['%s' % tool.extract_installed, '-xzvf', '%s' % input], shell=True).wait()
116 -# elif tool.extract_installed.endswith('tar'):
117 -# p = subprocess.Popen([])
118 -# else:
119 -# raise exceptions.CompressionNotSupportedError
120 -
121111 def init_compression_tool(self, extension, action):
122112 compression = {'gz': [['tar', 'tar'], ['7z', '7z']],
123113 'bz2': [['bzip2', 'bunzip2'], ['7z', '7z']],
@@ -138,6 +128,18 @@
139129 self.name = p
140130 self.program_installed = path
141131
 132+def launch_zip_extractor(location, filename, properties):
 133+ '''
 134+
 135+ '''
 136+ print 'Unzipping zip file'
 137+ stopwatch = timer.Timer()
 138+ log.log_to_mongo(properties, 'dataset', 'unpack', stopwatch, event='start')
 139+ compressor = Compressor(location, filename)
 140+ retcode = compressor.extract()
 141+ stopwatch.elapsed()
 142+ log.log_to_mongo(properties, 'dataset', 'unpack', stopwatch, event='finish')
 143+ return retcode
142144
143145 if __name__ == '__main__':
144146 c = Compressor('C:\Users\diederik.vanliere\Documents', 'django.zip')

Status & tagging log