def run(self):
        """Run script."""
        config = self.get_config()
        args = self.get_parser()

        if args.log:
            self.create_logger()

        self.logger.debug('-' * 10)

        # Set some vars
        self.input_dir = os.path.join(config.get('html5', 'input'), '')
        self.png_quality = config.get('html5', 'png_quality')

        # Do the stuff we came here to do
        png_files = self.get_files_matching('*.png')

        size_before = self.get_size(png_files)

        self.png_crush(png_files)

        size_after = self.get_size(png_files)

        kb_saved = (size_before - size_after) / 1024
        logmsg.info('%s Kb saved' % kb_saved)

        if args.all:
            jpg_files = self.get_files_matching('*.jpg')
            all_files = jpg_files  ## png_files + jpg_files
            size_before = self.get_size(all_files)
            self.image_optim(all_files)
            size_after = self.get_size(all_files)

            kb_saved = (size_before - size_after) / 1024
            logmsg.info('%s Kb saved' % kb_saved)
Esempio n. 2
0
    def copy_files(self):
        """Copy files."""
        dest = os.path.join(self.input_dir, 'js')

        if not os.path.isdir(dest):
            if self.verbose:
                logmsg.info('Creating "js" directory...')
            shutil.copytree(self.get_data('js'), dest)
        else:
            if self.verbose:
                logmsg.warning('"js" directory already exists')
Esempio n. 3
0
 def copy_files(self):
     """Copy quickstart files from data folder to the CWD."""
     logmsg.header('Copy quickstart files...', self.logger)
     # Loop through all non-hidden files in quickstart directory
     files = [f for f in os.listdir(self.get_data('quickstart')) if not f.startswith('.')]
     for filename in files:
         src = os.path.join(self.get_data('quickstart'), filename)
         dst = os.path.join(os.getcwd(), filename)
         if not os.path.isfile(filename):
             shutil.copy2(src, dst)
             logmsg.info('Copied "{0}"'.format(filename), self.logger)
         else:
             logmsg.warning('"{0}" already exists'.format(filename),
                            self.logger)