Beispiel #1
0
	def get_entry(self, name):
		"""Get CHM entry by name"""
		# show index page or any other substitute
		if name == '/':
			name = self.frontpage
		if name in self.templates or name == self.frontpage:
			return self.get_template(name)
		if name.lower() in [ os.path.join('/icons', icon.lower()) for icon in os.listdir(self.icons_dir) ]:
			return open(os.path.join(self.icons_dir, os.path.basename(name))).read()
		for e in self.entries:
			if e.lower() == name.lower():
				return CHMEntry(self, e, frontpage=self.frontpage).get()
		else:
			archmod.message(archmod.ERROR, 'NameError: There is no %s' % name)
Beispiel #2
0
	def do_GET(self):
		pagename = urllib.unquote(self.path.split('?')[0])
		if pagename == '/':
			mimetype = 'text/html'
		else:
			mimetype = mimetypes.guess_type(pagename)[0]

		self.send_response(200)
		self.send_header('Content-type', mimetype)
		self.end_headers()

		# get html data from CHM instance and write it into output
		try:
			self.wfile.write(self.server.CHM.get_entry(pagename))
		except NameError, msg:
			archmod.message(archmod.ERROR, 'NameError: %s' % msg)
Beispiel #3
0
    def do_GET(self):
        pagename = urllib.unquote(self.path.split('?')[0])
        if pagename == '/':
            mimetype = 'text/html'
        else:
            mimetype = mimetypes.guess_type(pagename)[0]

        self.send_response(200)
        self.send_header('Content-type', mimetype)
        self.end_headers()

        # get html data from CHM instance and write it into output
        try:
            self.wfile.write(self.server.CHM.get_entry(pagename))
        except NameError, msg:
            archmod.message(archmod.ERROR, 'NameError: %s' % msg)
Beispiel #4
0
 def get_entry(self, name):
     """Get CHM entry by name"""
     # show index page or any other substitute
     if name == '/':
         name = self.frontpage
     if name in self.templates or name == self.frontpage:
         return self.get_template(name)
     if name.lower() in [
             os.path.join('/icons', icon.lower())
             for icon in os.listdir(self.icons_dir)
     ]:
         return open(os.path.join(self.icons_dir,
                                  os.path.basename(name))).read()
     for e in self.entries:
         if e.lower() == name.lower():
             return CHMEntry(self, e, frontpage=self.frontpage).get()
     else:
         archmod.message(archmod.ERROR, 'NameError: There is no %s' % name)
Beispiel #5
0
def usage(code=archmod.OK, msg=''):
    """Show application usage and quit"""
    archmod.message(code, __doc__ % globals())
    archmod.message(code, msg)
    sys.exit(code)
Beispiel #6
0
    except getopt.error, msg:
        usage(archmod.ERROR, msg)

    class Options:
        mode = None  # EXTRACT or HTTPSERVER or other
        port = None  # HTTP port number
        chmfile = None  # CHM File to view/extract
        output = None  # Output file or directory

    options = Options()

    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage()
        elif opt in ('-V', '--version'):
            archmod.message(archmod.OK, archmod.__version__)
            sys.exit(archmod.OK)
        elif opt in ('-p', '--port'):
            if options.mode is not None:
                sys.exit('-x and -p or -c are mutually exclusive')
            options.mode = archmod.HTTPSERVER
            try:
                options.port = int(arg)
            except ValueError, msg:
                sys.exit('Invalid port number: %s' % msg)
        elif opt in ('-c', '--convert'):
            if options.mode is not None:
                sys.exit('-x and -p or -c are mutually exclusive')
            options.mode = archmod.output_format(str(arg))
        elif opt in ('-x', '--extract'):
            if options.mode is not None:
Beispiel #7
0
def usage(code=archmod.OK, msg=''):
    """Show application usage and quit"""
    archmod.message(code, __doc__ % globals())
    archmod.message(code, msg)
    sys.exit(code)
Beispiel #8
0
    except getopt.error, msg:
        usage(archmod.ERROR, msg)

    class Options:
        mode = None        # EXTRACT or HTTPSERVER or other
        port = None        # HTTP port number
        chmfile = None     # CHM File to view/extract
        output = None      # Output file or directory

    options = Options()

    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage()
        elif opt in ('-V', '--version'):
            archmod.message(archmod.OK, archmod.__version__)
            sys.exit(archmod.OK)
        elif opt in ('-p', '--port'):
            if options.mode is not None:
                sys.exit('-x and -p or -c are mutually exclusive')
            options.mode = archmod.HTTPSERVER
            try:
                options.port = int(arg)
            except ValueError, msg:
                sys.exit('Invalid port number: %s' % msg)
        elif opt in ('-c', '--convert'):
            if options.mode is not None:
                sys.exit('-x and -p or -c are mutually exclusive')
            options.mode = archmod.output_format(str(arg))
        elif opt in ('-x', '--extract'):
            if options.mode is not None: