mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-03 19:17:02 -05:00 
			
		
		
		
	Move hosting script to python 3
This commit is contained in:
		
							parent
							
								
									86300075cf
								
							
						
					
					
						commit
						64b56e4aec
					
				@ -1,6 +1,5 @@
 | 
				
			|||||||
#!/usr/bin/env python2
 | 
					#!/usr/bin/env python
 | 
				
			||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
 | 
					# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
 | 
				
			||||||
from __future__ import absolute_import, division, print_function, unicode_literals
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
__license__ = 'GPL v3'
 | 
					__license__ = 'GPL v3'
 | 
				
			||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
 | 
					__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
 | 
				
			||||||
@ -13,27 +12,34 @@ from subprocess import check_call
 | 
				
			|||||||
from collections import OrderedDict
 | 
					from collections import OrderedDict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ReadFileWithProgressReporting(file):  # {{{
 | 
					class ReadFileWithProgressReporting:  # {{{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, path, mode='rb'):
 | 
					    def __init__(self, path, mode='rb'):
 | 
				
			||||||
        file.__init__(self, path, mode)
 | 
					        self.fobj = open(path, mode)
 | 
				
			||||||
        self.seek(0, os.SEEK_END)
 | 
					        self.fobj.seek(0, os.SEEK_END)
 | 
				
			||||||
        self._total = self.tell()
 | 
					        self._total = self.tell()
 | 
				
			||||||
        self.seek(0)
 | 
					        self.fobj.seek(0)
 | 
				
			||||||
        self.start_time = time.time()
 | 
					        self.start_time = time.time()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __enter__(self):
 | 
				
			||||||
 | 
					        return self
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __exit__(self, *a):
 | 
				
			||||||
 | 
					        self.fobj.close()
 | 
				
			||||||
 | 
					        del self.fobj
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __len__(self):
 | 
					    def __len__(self):
 | 
				
			||||||
        return self._total
 | 
					        return self._total
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def read(self, size):
 | 
					    def read(self, size):
 | 
				
			||||||
        data = file.read(self, size)
 | 
					        data = self.fobj.read(size)
 | 
				
			||||||
        if data:
 | 
					        if data:
 | 
				
			||||||
            self.report_progress(len(data))
 | 
					            self.report_progress(len(data))
 | 
				
			||||||
        return data
 | 
					        return data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def report_progress(self, size):
 | 
					    def report_progress(self, size):
 | 
				
			||||||
        sys.stdout.write(b'\x1b[s')
 | 
					        sys.stdout.write('\x1b[s')
 | 
				
			||||||
        sys.stdout.write(b'\x1b[K')
 | 
					        sys.stdout.write('\x1b[K')
 | 
				
			||||||
        frac = float(self.tell()) / self._total
 | 
					        frac = float(self.tell()) / self._total
 | 
				
			||||||
        mb_pos = self.tell() / float(1024**2)
 | 
					        mb_pos = self.tell() / float(1024**2)
 | 
				
			||||||
        mb_tot = self._total / float(1024**2)
 | 
					        mb_tot = self._total / float(1024**2)
 | 
				
			||||||
@ -46,7 +52,7 @@ class ReadFileWithProgressReporting(file):  # {{{
 | 
				
			|||||||
            '  %.1f%%   %.1f/%.1fMB %.1f KB/sec    %d minutes, %d seconds left' %
 | 
					            '  %.1f%%   %.1f/%.1fMB %.1f KB/sec    %d minutes, %d seconds left' %
 | 
				
			||||||
            (frac * 100, mb_pos, mb_tot, kb_rate, eta_m, eta_s)
 | 
					            (frac * 100, mb_pos, mb_tot, kb_rate, eta_m, eta_s)
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        sys.stdout.write(b'\x1b[u')
 | 
					        sys.stdout.write('\x1b[u')
 | 
				
			||||||
        if self.tell() >= self._total:
 | 
					        if self.tell() >= self._total:
 | 
				
			||||||
            sys.stdout.write('\n')
 | 
					            sys.stdout.write('\n')
 | 
				
			||||||
            t = int(time.time() - self.start_time) + 1
 | 
					            t = int(time.time() - self.start_time) + 1
 | 
				
			||||||
 | 
				
			|||||||
@ -149,7 +149,7 @@ def run_remote_upload(args):
 | 
				
			|||||||
    print('Running remotely:', ' '.join(args))
 | 
					    print('Running remotely:', ' '.join(args))
 | 
				
			||||||
    subprocess.check_call([
 | 
					    subprocess.check_call([
 | 
				
			||||||
        'ssh', '-x', '%s@%s' % (STAGING_USER, STAGING_HOST), 'cd', STAGING_DIR, '&&',
 | 
					        'ssh', '-x', '%s@%s' % (STAGING_USER, STAGING_HOST), 'cd', STAGING_DIR, '&&',
 | 
				
			||||||
        'python2', 'hosting.py'
 | 
					        'python', 'hosting.py'
 | 
				
			||||||
    ] + args)
 | 
					    ] + args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user