Esempio n. 1
0
	def slot_choose_temp_dir(self):
		dialog = QtGui.QFileDialog()
		dialog.setFileMode(QtGui.QFileDialog.Directory)
		dialog.setDirectory(self.temp_dir.displayText())
		temp_dir = unicode(dialog.getExistingDirectory(options=QtGui.QFileDialog.ShowDirsOnly))
		temp_dir = temp_dir.replace('/','\\')
		
		if temp_dir:
			if utils.get_free_space(temp_dir) < 200*1024**2: # 200 MB
				log.warning("The Directory has less than 200 MB available. Application may not function properly.")
				QtGui.QMessageBox.warning(self, tr("Warning"), tr("The Directory has less than 200 MB available. Application may not function properly."), QtGui.QMessageBox.Ok)
			log.debug("temp_dir is set to: %s" % temp_dir)
			self.temp_dir.setText(temp_dir)
Esempio n. 2
0
    def cache(self, location, active, size, free):
        self.cache_active = active
        self.cache_size = size
        self.cache_free = free
        self.cache_filled = 0
        self.cache_list = []
        self.cache_hit = 0
        self.cache_miss = 0
        self.cache_discard = 0
        self.cache_maxsize = size
        self.cache_location = location

        self.cache_location = os.path.join(
            self.cache_location,
            ComicStreamerConfig()['database']['engine'])

        try:
            if not os.path.exists(self.cache_location):
                os.makedirs(self.cache_location)
        except:
            self.cache_active = False

        for subdir, dirs, files in os.walk(self.cache_location):
            # why is this here?
            if os.path.split(subdir)[-1] == 'cache': continue
            for file in files:
                cachefile = os.path.join(subdir, file)
                cache_file_size = utils.file_size_bytes(cachefile)
                #print (os.path.split(subdir)[-1])
                #print file
                self.cache_list += [(os.path.split(subdir)[-1], file,
                                     cache_file_size,
                                     os.path.getmtime(cachefile))]
                self.cache_filled += cache_file_size

        self.cache_list = sorted(self.cache_list, key=lambda x: int(x[3]))

        cache_free_size = utils.get_free_space(self.cache_location)
        self.cache_maxsize = cache_free_size - self.cache_free * 1048576 - self.cache_filled
        if self.cache_maxsize < 0:
            self.cache_maxsize += self.cache_delete(abs(self.cache_maxsize))
            if self.cache_maxsize < 0:
                self.cache_maxsize = 0
        if self.cache_size > 0 and self.cache_maxsize > self.cache_size * 1048576:
            self.cache_maxsize = self.cache_size
        else:
            self.cache_maxsize = (self.cache_maxsize +
                                  self.cache_filled) / 1048576
        """
Esempio n. 3
0
    def cache(self,location,active,size,free):
        self.cache_active = active
        self.cache_size = size
        self.cache_free = free
        self.cache_filled = 0
        self.cache_list = []
        self.cache_hit = 0
        self.cache_miss = 0
        self.cache_discard = 0
        self.cache_maxsize = size
        self.cache_location = location
        
        self.cache_location = os.path.join(self.cache_location,ComicStreamerConfig()['database']['engine'])
        
        try:
            if not os.path.exists(self.cache_location):
                os.makedirs(self.cache_location)
        except:
            self.cache_active = False;
        
        for subdir, dirs, files in os.walk(self.cache_location):
            # why is this here?
            if os.path.split(subdir)[-1] == 'cache': continue
            for file in files:
                cachefile = os.path.join(subdir, file)
                cache_file_size = utils.file_size_bytes(cachefile)
                #print (os.path.split(subdir)[-1])
                #print file
                self.cache_list += [(os.path.split(subdir)[-1],file,cache_file_size,os.path.getmtime(cachefile))]
                self.cache_filled += cache_file_size

        self.cache_list = sorted(self.cache_list, key = lambda x: int(x[3]))
        
        cache_free_size = utils.get_free_space(self.cache_location)
        self.cache_maxsize = cache_free_size - self.cache_free*1048576 - self.cache_filled
        if self.cache_maxsize < 0:
            self.cache_maxsize += self.cache_delete(abs(self.cache_maxsize))
            if self.cache_maxsize < 0:
                self.cache_maxsize = 0
        if self.cache_size > 0 and self.cache_maxsize > self.cache_size*1048576:
                self.cache_maxsize = self.cache_size
        else:
            self.cache_maxsize = (self.cache_maxsize + self.cache_filled) / 1048576
    
        """
Esempio n. 4
0
    def slot_choose_temp_dir(self):
        dialog = QtGui.QFileDialog()
        dialog.setFileMode(QtGui.QFileDialog.Directory)
        dialog.setDirectory(self.temp_dir.displayText())
        temp_dir = unicode(
            dialog.getExistingDirectory(
                options=QtGui.QFileDialog.ShowDirsOnly))
        temp_dir = temp_dir.replace('/', '\\')

        if temp_dir:
            if utils.get_free_space(temp_dir) < 200 * 1024**2:  # 200 MB
                log.warning(
                    "The Directory has less than 200 MB available. Application may not function properly."
                )
                QtGui.QMessageBox.warning(
                    self, tr("Warning"),
                    tr("The Directory has less than 200 MB available. Application may not function properly."
                       ), QtGui.QMessageBox.Ok)
            log.debug("temp_dir is set to: %s" % temp_dir)
            self.temp_dir.setText(temp_dir)
Esempio n. 5
0
    def run(self):
        args = __main__.args  # FIXME:
        total_files = self.mInQueue.qsize()
        while True:
            file_name = self.mInQueue.get()
            if file_name is None:
                break
            start_time = time.time()
            self.createFile(file_name, BINARY_PATTERN, args.file_size)
            self.mOutList.append(file_name)
            elapsed_time = time.time() - start_time
            files_left = self.mInQueue.qsize()
            percent = int(50 * (total_files - files_left) / total_files)
            print_verbose(
                "[{:02d}%,{},{} free] Created file {}  [{}/s]".format(
                    percent, files_left,
                    format_human(get_free_space(args.work_dir)), file_name,
                    format_human(int(args.file_size / elapsed_time))))

            files_left -= 1
            self.mInQueue.task_done()
Esempio n. 6
0
    def create(self):
        """
        Create a poolset file with basic space validation. If CREATE arguments
        ware passed to parts, create parts files as well.
        """
        self._check_pools_size()
        required_size = self._get_required_size()
        free_space = get_free_space()
        if required_size > free_space:
            fail('Not enough space available to create parts files. There is '
                 '{}, and poolset requires {}'.format(free_space,
                                                      required_size))

        for part in self.parts:
            part._process(self.ctx)
        for replica in self.replicas:
            for part in replica:
                part._process(self.ctx)

        self.options = list(set(self.options))

        poolsetpath = os.path.join(self.ctx.testdir, self.path)
        with open(poolsetpath, 'w') as poolset:
            print('PMEMPOOLSET', end='\n\n', file=poolset)

            for option in self.options:
                print('OPTION', option, end='\n\n', file=poolset)

            for part in self.parts:
                print(part, file=poolset)
            print(file=poolset)

            for replica in self.replicas:
                print("REPLICA", file=poolset)
                for part in replica:
                    print(part, file=poolset)
                print(file=poolset)

            for remote in self.remote:
                print("REPLICA", remote[1], remote[0], file=poolset)
Esempio n. 7
0
    def create(self):
        """
        Create a poolset file with basic space validation. If CREATE arguments
        ware passed to parts, create parts files as well.
        """
        self._check_pools_size()
        required_size = self._get_required_size()
        free_space = get_free_space()
        if required_size > free_space:
            fail('Not enough space available to create parts files. There is '
                 '{}, and poolset requires {}'.format(free_space,
                                                      required_size))

        for part in self.parts:
            part._process(self.ctx)
        for replica in self.replicas:
            for part in replica:
                part._process(self.ctx)

        self.options = list(set(self.options))

        poolsetpath = os.path.join(self.ctx.testdir, self.path)
        with open(poolsetpath, 'w') as poolset:
            print('PMEMPOOLSET', end='\n\n', file=poolset)

            for option in self.options:
                print('OPTION', option, end='\n\n', file=poolset)

            for part in self.parts:
                print(part, file=poolset)
            print(file=poolset)

            for replica in self.replicas:
                print("REPLICA", file=poolset)
                for part in replica:
                    print(part, file=poolset)
                print(file=poolset)

            for remote in self.remote:
                print("REPLICA", remote[1], remote[0], file=poolset)
Esempio n. 8
0
def sanity_check():
	"Sanity Check for script."
	config.count_application_runs += 1
	_warnings = []
	
	### LOCAL CHECKS ###
	
	# Windows version check
	winver = sys.getwindowsversion()
	log.debug('Running iQuality v%s (r%d) on Windows %d.%d.%d %s' % (__version__, __rev__, winver.major, winver.minor, winver.build, winver.service_pack))
	
	# Python version check
	if sys.version_info < (2, 6) or sys.version_info >= (3, 0):
		msg = "must use python 2.7"
		log.critical(msg)
		raise Exception(msg)
	log.debug('CPython version is %d.%d.%d' % (sys.version_info.major, sys.version_info.minor, sys.version_info.micro))
	log.debug('PyQt version is %s, Qt version is %s' % (QtCore.PYQT_VERSION_STR, QtCore.QT_VERSION_STR))
		
	# youtube-dl check
	try:
		import youtube_dl
		log.debug("youtube-dl version is %s" % youtube_dl.__version__)
	except ImportError:
		log.warning("Could not load the youtube-dl module")
		
	# Phonon version check
	try:
		from PyQt4.phonon import Phonon
		if Phonon.BackendCapabilities.isMimeTypeAvailable('video/x-flv'):
			log.debug('Phonon version is %s. video/x-flv is supported.' % Phonon.phononVersion())
		else:
			log.warning('Phonon version is %s. video/x-flv is not supported.' % Phonon.phononVersion())
	except ImportError:
		log.warning("Could not load the phonon module")
	
	# Free space check
	freespace = utils.get_free_space(config.temp_dir)
	if freespace < 200*1024**2: # 200 MB
		drive = os.path.splitdrive(config.temp_dir)[0]
		log.warning("There are less than 200MB available in drive %s (%.2fMB left)." % (drive, freespace/1024.0**2))
		_warnings.append(NoSpaceWarning(drive, freespace))

	# iTunes' availablity check
	itunesPath = r'%s\My Documents\My Music\iTunes\iTunes Media\Automatically Add to iTunes' % utils.get_home_dir()
	if not os.path.exists(itunesPath):
		config.is_itunes_installed = False
		if config.post_download_action == 'addItunes':
			config.post_download_action = 'ask'
		log.warning("iTunes Media not found. setting is_itunes_installed to False")
		
	# Context Menu check
	try: # IMPROVE: REMOVE THE TRY-EXCEPT BLOCK
		if config.id3editor_in_context_menu and not utils.check_context_menu_status():
			log.debug("Registering Context Menu Object...")
			try:
				utils.register_with_context_menu()
			except WindowsError, e:
				if e.winerror == 5: # Access is denied
					log.debug("Access is denied. Setting id3editor_in_context_menu to False.")
					config.id3editor_in_context_menu = False
				else:
					raise
		if not config.id3editor_in_context_menu and utils.check_context_menu_status():
			log.debug("Unregistering Context Menu Object...")
			try:
				utils.unregister_with_context_menu()
			except WindowsError, e:
				if e.winerror == 5: # Access is denied
					log.debug("Access is denied. Setting id3editor_in_context_menu to True.")
					config.id3editor_in_context_menu = True
				else:
					raise
Esempio n. 9
0
    def cache_load(self, comic_id, page_number, path):
        if self.cache_active:
            cachepath = self.cache_location + "/" + comic_id + "/"
            cachefile = cachepath + str(page_number)
            if not os.path.exists(cachepath):
                os.makedirs(cachepath)
            if not os.path.isfile(cachefile):
                ca = self.getComicArchive(comic_id,path)
                image = self.isBlacklist(ca.getPage(int(page_number)))
                
                # auto convert webp (disable for chunky or fix web book reader)
                image = utils.webp_patch_convert(image)

                cache_file_size = len(image)
                
                cache_free_size = utils.get_free_space(self.cache_location)
                x = cache_free_size - self.cache_free*1048576 - self.cache_filled
                
                if x < 0:
                    cache_free_size += self.cache_delete(abs(x))
                
                deleted = 0
                if self.cache_size > 0 and self.cache_filled + cache_file_size > self.cache_size*1048576:
                    deleted = self.cache_delete(cache_file_size)
                    cache_free_size += deleted
                else:
                    deleted = cache_file_size
                
                self.cache_maxsize = cache_free_size - self.cache_free*1048576 - self.cache_filled
                if self.cache_maxsize < 0:
                    self.cache_maxsize = 0
                if self.cache_size > 0 and self.cache_maxsize > self.cache_size*1048576:
                        self.cache_maxsize = self.cache_size
                else:
                    self.cache_maxsize = (self.cache_maxsize + self.cache_filled) / 1048576
            
                
                self.cache_miss += 1
                if cache_file_size <= deleted:
                    try:
                        file = open(cachefile, "w")
                        file.write(image)
                        file.close()
                        self.cache_filled += cache_file_size
                        self.cache_list += [(comic_id,page_number,cache_file_size,os.path.getmtime(cachefile))]
                    except:
                        # logging would be better...
                        print "Could not write to cache: " + cachefile
                
                # DEBUG
                """
                if self.cache_size == 0:
                    print "Size: Fill"
                else:
                    print "Size: " + str(self.cache_size) + "mb"
                print "Free: " + str(self.cache_free) + "mb"
                print "Free FS: " + str(utils.get_free_space(self.cache_location)/1024/1024) + "mb"
                print "Filled: " + str(self.cache_filled/1024/1024) + "mb"
                print "Files: " + str(len(self.cache_list))
                print "Remaining: " + str(x/1024/1024) + "mb"
                """
            else:
                file = open(cachefile, "r")
                image = file.read()
                self.cache_hit += 1
                # DEBUG
                #print "Hit"
        else:
            ca = self.getComicArchive(comic_id,path)
            # auto convert webp (disable for chunky or fix web book reader)
            image = utils.webp_patch_convert(self.isBlacklist(ca.getPage(int(page_number))))

        return image
Esempio n. 10
0
    def cache_load(self, comic_id, page_number, path):
        if self.cache_active:
            cachepath = self.cache_location + "/" + comic_id + "/"
            cachefile = cachepath + str(page_number)
            if not os.path.exists(cachepath):
                os.makedirs(cachepath)
            if not os.path.isfile(cachefile):
                ca = self.getComicArchive(comic_id, path)
                image = self.isBlacklist(ca.getPage(int(page_number)))

                # auto convert webp (disable for chunky or fix web book reader)
                image = utils.webp_patch_convert(image)

                cache_file_size = len(image)

                cache_free_size = utils.get_free_space(self.cache_location)
                x = cache_free_size - self.cache_free * 1048576 - self.cache_filled

                if x < 0:
                    cache_free_size += self.cache_delete(abs(x))

                deleted = 0
                if self.cache_size > 0 and self.cache_filled + cache_file_size > self.cache_size * 1048576:
                    deleted = self.cache_delete(cache_file_size)
                    cache_free_size += deleted
                else:
                    deleted = cache_file_size

                self.cache_maxsize = cache_free_size - self.cache_free * 1048576 - self.cache_filled
                if self.cache_maxsize < 0:
                    self.cache_maxsize = 0
                if self.cache_size > 0 and self.cache_maxsize > self.cache_size * 1048576:
                    self.cache_maxsize = self.cache_size
                else:
                    self.cache_maxsize = (self.cache_maxsize +
                                          self.cache_filled) / 1048576

                self.cache_miss += 1
                if cache_file_size <= deleted:
                    try:
                        file = open(cachefile, "w")
                        file.write(image)
                        file.close()
                        self.cache_filled += cache_file_size
                        self.cache_list += [(comic_id, page_number,
                                             cache_file_size,
                                             os.path.getmtime(cachefile))]
                    except:
                        # logging would be better...
                        print "Could not write to cache: " + cachefile

                # DEBUG
                """
                if self.cache_size == 0:
                    print "Size: Fill"
                else:
                    print "Size: " + str(self.cache_size) + "mb"
                print "Free: " + str(self.cache_free) + "mb"
                print "Free FS: " + str(utils.get_free_space(self.cache_location)/1024/1024) + "mb"
                print "Filled: " + str(self.cache_filled/1024/1024) + "mb"
                print "Files: " + str(len(self.cache_list))
                print "Remaining: " + str(x/1024/1024) + "mb"
                """
            else:
                file = open(cachefile, "r")
                image = file.read()
                self.cache_hit += 1
                # DEBUG
                #print "Hit"
        else:
            ca = self.getComicArchive(comic_id, path)
            # auto convert webp (disable for chunky or fix web book reader)
            image = utils.webp_patch_convert(
                self.isBlacklist(ca.getPage(int(page_number))))

        return image
Esempio n. 11
0
 #                     tcompact=utils.convert_bytes(os.path.getsize(utils.get_zip_file_name())),
 #                      tavail=utils.get_free_space(config.TARGET_BKP_DIR),
 #                      fbkp_name=utils.get_zip_file_name().,
 #                      cpori=config.CP_ORIGEM,
 #                      cpdest=config.CP_DESTINO)
 print 'ptm='+config.PTM_NAME
 print 'data='+inicio.date().strftime("%d/%m/%Y")
 print 'inicio='+inicio.time().strftime("%H:%M:%S")
 print 'fim='+fim.time().strftime("%H:%M:%S")
 print 'tempo='+str(fim-inicio)
 print 'tfiles='+str(num_files_total)
 print 'tfcopied='+str(num_files_ok)
 print 'tfail='+str(num_files_fail)
 print 'tori='+str(utils.convert_bytes(total_size_bytes))
 print 'tcompact='+str(utils.convert_bytes(os.path.getsize(utils.get_zip_file_name() ) ) )
 print 'tavail='+str(utils.get_free_space(config.TARGET_BKP_DIR))
 print 'fbkp_name='+utils.get_zip_file_name()
 print 'cpori='+config.CP_ORIGEM
 print 'cpdest='+config.CP_DESTINO
 
          
 msg = []
 msg.append('PTM:'+config.PTM_NAME)
 
 msg.append(u'Data:'+inicio.date().strftime("%d/%m/%Y"))
 msg.append(u'Hora de Início:'+inicio.time().strftime("%H:%M:%S"))
 msg.append(u'Hora de Término:'+fim.time().strftime("%H:%M:%S"))
 msg.append(u'Tempo do Backup:'+str(fim-inicio))
 msg.append(u'Número Total de arquivos:'+str(num_files_total))
 msg.append(u'Número de arquivos copiados:'+str(num_files_ok))
 msg.append(u'Número de arquivos com falha:'+str(num_files_fail))
Esempio n. 12
0
def sanity_check():
    "Sanity Check for script."
    config.count_application_runs += 1
    _warnings = []

    ### LOCAL CHECKS ###

    # Windows version check
    winver = sys.getwindowsversion()
    log.debug('Running iQuality v%s (r%d) on Windows %d.%d.%d %s' %
              (__version__, __rev__, winver.major, winver.minor, winver.build,
               winver.service_pack))

    # Python version check
    if sys.version_info < (2, 6) or sys.version_info >= (3, 0):
        msg = "must use python 2.7"
        log.critical(msg)
        raise Exception(msg)
    log.debug('CPython version is %d.%d.%d' %
              (sys.version_info.major, sys.version_info.minor,
               sys.version_info.micro))
    log.debug('PyQt version is %s, Qt version is %s' %
              (QtCore.PYQT_VERSION_STR, QtCore.QT_VERSION_STR))

    # youtube-dl check
    try:
        import youtube_dl
        log.debug("youtube-dl version is %s" % youtube_dl.__version__)
    except ImportError:
        log.warning("Could not load the youtube-dl module")

    # Phonon version check
    try:
        from PyQt4.phonon import Phonon
        if Phonon.BackendCapabilities.isMimeTypeAvailable('video/x-flv'):
            log.debug('Phonon version is %s. video/x-flv is supported.' %
                      Phonon.phononVersion())
        else:
            log.warning('Phonon version is %s. video/x-flv is not supported.' %
                        Phonon.phononVersion())
    except ImportError:
        log.warning("Could not load the phonon module")

    # Free space check
    freespace = utils.get_free_space(config.temp_dir)
    if freespace < 200 * 1024**2:  # 200 MB
        drive = os.path.splitdrive(config.temp_dir)[0]
        log.warning(
            "There are less than 200MB available in drive %s (%.2fMB left)." %
            (drive, freespace / 1024.0**2))
        _warnings.append(NoSpaceWarning(drive, freespace))

    # iTunes' availablity check
    itunesPath = r'%s\My Documents\My Music\iTunes\iTunes Media\Automatically Add to iTunes' % utils.get_home_dir(
    )
    if not os.path.exists(itunesPath):
        config.is_itunes_installed = False
        if config.post_download_action == 'addItunes':
            config.post_download_action = 'ask'
        log.warning(
            "iTunes Media not found. setting is_itunes_installed to False")

    # Context Menu check
    try:  # IMPROVE: REMOVE THE TRY-EXCEPT BLOCK
        if config.id3editor_in_context_menu and not utils.check_context_menu_status(
        ):
            log.debug("Registering Context Menu Object...")
            try:
                utils.register_with_context_menu()
            except WindowsError, e:
                if e.winerror == 5:  # Access is denied
                    log.debug(
                        "Access is denied. Setting id3editor_in_context_menu to False."
                    )
                    config.id3editor_in_context_menu = False
                else:
                    raise
        if not config.id3editor_in_context_menu and utils.check_context_menu_status(
        ):
            log.debug("Unregistering Context Menu Object...")
            try:
                utils.unregister_with_context_menu()
            except WindowsError, e:
                if e.winerror == 5:  # Access is denied
                    log.debug(
                        "Access is denied. Setting id3editor_in_context_menu to True."
                    )
                    config.id3editor_in_context_menu = True
                else:
                    raise