Beispiel #1
0
	def write_chm(self, book, path):
		if not sys.platform.startswith('win'):
			raise NotImplementedError, 'Only supported on Windows platform'
		
		dir_ = tempfile.mkdtemp()
		
		name = book.name
			
		formatter = Formatter(book, name)
		
		hhp_name = os.path.join(dir_, name + '.hhp')
		fp = file(hhp_name, 'wt')
		formatter.write_hhp(fp)
		fp.close()
		
		fp = file(os.path.join(dir_, name + '.hhc'), 'wt')
		formatter.write_hhc(fp)
		fp.close()
		
		fp = file(os.path.join(dir_, name + '.hhk'), 'wt')
		formatter.write_hhk(fp)
		fp.close()
		
		for pname in book.archive:
			# FIXME: make parent dirs
			fp = file(os.path.join(dir_, pname), 'wb')
			fp.write(book.archive[pname].read())
			fp.close()

		os.spawnl(os.P_WAIT, 'C:\\Program Files\\HTML Help Workshop\\hhc.exe', 'hhc.exe', hhp_name)

		shutil.move(os.path.join(dir_, name + '.chm'), path)
		
		shutil.rmtree(dir_)
Beispiel #2
0
    def write_chm(self, book, path):
        dir_ = tempfile.mkdtemp()

        name = book.name

        formatter = Formatter(book, name)

        hhp_name = os.path.join(dir_, name + '.hhp')
        fp = file(hhp_name, 'wt')
        formatter.write_hhp(fp)
        fp.close()

        fp = file(os.path.join(dir_, name + '.hhc'), 'wt')
        formatter.write_hhc(fp)
        fp.close()

        fp = file(os.path.join(dir_, name + '.hhk'), 'wt')
        formatter.write_hhk(fp)
        fp.close()

        for pname in book.archive:
            fullpath = os.path.join(dir_, pname)
            fulldir = os.path.dirname(fullpath)
            if not os.path.exists(fulldir):
                os.makedirs(fulldir)
            fp = file(fullpath, 'wb')
            fp.write(book.archive[pname].read())
            fp.close()

        hhc = 'C:\\Program Files\\HTML Help Workshop\\hhc.exe'
        if sys.platform.startswith('win'):
            subprocess.call([hhc, hhp_name])
        else:
            hhp_name = subprocess.Popen(
                ["winepath", "-w", hhp_name],
                stdout=subprocess.PIPE).communicate()[0]
            hhp_name = hhp_name.rstrip('\r\n')
            subprocess.call(['wine', hhc, hhp_name])

        shutil.move(os.path.join(dir_, name + '.chm'), path)

        shutil.rmtree(dir_)
Beispiel #3
0
	def write_htb(self, book, path):
		zip_ = zipfile.ZipFile(path, 'w')
	
		name = book.name
			
		formatter = Formatter(book, name)
		
		fp = StringIO()
		formatter.write_hhp(fp)
		zip_.writestr(name + '.hhp', fp.getvalue())
		
		fp = StringIO()
		formatter.write_hhc(fp)
		zip_.writestr(name + '.hhc', fp.getvalue())
		
		fp = StringIO()
		formatter.write_hhk(fp)
		zip_.writestr(name + '.hhk', fp.getvalue())
		
		for name in book.archive:
			fp = book.archive[name]
			zip_.writestr(name, fp.read())
Beispiel #4
0
	def write_chm(self, book, path):
		dir_ = tempfile.mkdtemp()
		
		name = book.name
			
		formatter = Formatter(book, name)
		
		hhp_name = os.path.join(dir_, name + '.hhp')
		fp = file(hhp_name, 'wt')
		formatter.write_hhp(fp)
		fp.close()
		
		fp = file(os.path.join(dir_, name + '.hhc'), 'wt')
		formatter.write_hhc(fp)
		fp.close()
		
		fp = file(os.path.join(dir_, name + '.hhk'), 'wt')
		formatter.write_hhk(fp)
		fp.close()
		
		for pname in book.archive:
			fullpath = os.path.join(dir_, pname)
			fulldir = os.path.dirname(fullpath)
			if not os.path.exists(fulldir):
				os.makedirs(fulldir)
			fp = file(fullpath, 'wb')
			fp.write(book.archive[pname].read())
			fp.close()

		hhc = 'C:\\Program Files\\HTML Help Workshop\\hhc.exe'
		if sys.platform.startswith('win'):
			subprocess.call([hhc, hhp_name])
		else:
			hhp_name = subprocess.Popen(["winepath", "-w", hhp_name], stdout=subprocess.PIPE).communicate()[0]
			hhp_name = hhp_name.rstrip('\r\n')
			subprocess.call(['wine', hhc, hhp_name])

		shutil.move(os.path.join(dir_, name + '.chm'), path)
		
		shutil.rmtree(dir_)