예제 #1
0
파일: CHM.py 프로젝트: amitkr/archmage
	def htmldoc(self, output, format=archmod.CHM2HTML):
		"""CHM to other file formats converter using htmldoc"""
		# Extract CHM content into temporary directory
		output = output.replace(' ', '_')
		tempdir = tempfile.mkdtemp(prefix=output.rsplit('.', 1)[0])
		self.extract_entries(entries=self.html_files, destdir=tempdir, correct=True)
		# List of temporary files
		files = [ os.path.abspath(tempdir + file.lower()) for file in self.html_files ]
		if format == archmod.CHM2HTML:
			options = self.chmtohtml
			# change output from single html file to a directory with html file and images
			if self.image_files:
				dirname = archmod.file2dir(output)
				if os.path.exists(dirname):
					sys.exit('%s is already exists' % dirname)
				# Extract image files
				os.mkdir(dirname)
				# Extract all images
				for key, value in self.image_files.items():
					self.extract_entry(entry=key, output_file=value, destdir=dirname)
				# Fix output file name
				output = os.path.join(dirname, output)
		elif format == archmod.CHM2PDF:
			options = self.chmtopdf
			if self.image_files:
				# Extract all images
				for key, value in self.image_files.items():
					self.extract_entry(entry=key, output_file=key.lower(), destdir=tempdir)
		htmldoc(files, self.htmldoc_exec, options, self.toclevels, output)
		# Remove temporary files
		shutil.rmtree(path=tempdir)
예제 #2
0
 def htmldoc(self, output, format=archmod.CHM2HTML):
     """CHM to other file formats converter using htmldoc"""
     # Extract CHM content into temporary directory
     output = output.replace(' ', '_')
     tempdir = tempfile.mkdtemp(prefix=output.rsplit('.', 1)[0])
     self.extract_entries(entries=self.html_files,
                          destdir=tempdir,
                          correct=True)
     # List of temporary files
     files = [
         os.path.abspath(tempdir + file.lower()) for file in self.html_files
     ]
     if format == archmod.CHM2HTML:
         options = self.chmtohtml
         # change output from single html file to a directory with html file and images
         if self.image_files:
             dirname = archmod.file2dir(output)
             if os.path.exists(dirname):
                 sys.exit('%s is already exists' % dirname)
             # Extract image files
             os.mkdir(dirname)
             # Extract all images
             for key, value in self.image_files.items():
                 self.extract_entry(entry=key,
                                    output_file=value,
                                    destdir=dirname)
             # Fix output file name
             output = os.path.join(dirname, output)
     elif format == archmod.CHM2PDF:
         options = self.chmtopdf
         if self.image_files:
             # Extract all images
             for key, value in self.image_files.items():
                 self.extract_entry(entry=key,
                                    output_file=key.lower(),
                                    destdir=tempdir)
     htmldoc(files, self.htmldoc_exec, options, self.toclevels, output)
     # Remove temporary files
     shutil.rmtree(path=tempdir)
예제 #3
0
파일: cli.py 프로젝트: wzugang/archmage
    # Sanity checks
    if options.mode is None:
        # Set default option
        options.mode = archmod.EXTRACT

    if not args:
        sys.exit('No CHM file was specified!')
    else:
        # Get CHM file name from command line
        options.chmfile = args.pop(0)

    # if CHM content should be extracted
    if options.mode == archmod.EXTRACT:
        if not args:
            options.output = archmod.file2dir(options.chmfile)
        else:
            # get output directory from command line
            options.output = args.pop(0)
    # or converted into another file format
    elif options.mode in (archmod.CHM2TXT, archmod.CHM2HTML, archmod.CHM2PDF):
        if not args:
            options.output = archmod.output_file(options.chmfile, options.mode)
        else:
            # get output filename from command line
            options.output = args.pop(0)

    # Any other arguments are invalid
    if args:
        sys.exit('Invalid arguments: ' + archmod.COMMASPACE.join(args))
예제 #4
0
파일: cli.py 프로젝트: Searcher23/archmage
    # Sanity checks
    if options.mode is None:
        # Set default option
        options.mode = archmod.EXTRACT

    if not args:
        sys.exit('No CHM file was specified!')
    else:
        # Get CHM file name from command line
        options.chmfile = args.pop(0)

    # if CHM content should be extracted
    if options.mode == archmod.EXTRACT:
        if not args:
            options.output = archmod.file2dir(options.chmfile)
        else:
            # get output directory from command line
            options.output = args.pop(0)
    # or converted into another file format
    elif options.mode in (archmod.CHM2TXT, archmod.CHM2HTML, archmod.CHM2PDF):
        if not args:
            options.output = archmod.output_file(options.chmfile, options.mode)
        else:
            # get output filename from command line
            options.output = args.pop(0)

    # Any other arguments are invalid
    if args:
        sys.exit('Invalid arguments: ' + archmod.COMMASPACE.join(args))