__init__.py :  » Development » arCHMage » archmage-0.2.4 » archmod » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » arCHMage 
arCHMage » archmage 0.2.4 » archmod » __init__.py
__all__ = ['CHM', 'CHMServer', 'mod_chm']
__version__ = '0.2.4'

import sys, os

# Return codes
OK = 0
ERROR = 1

# Global variables
EXTRACT = 1    # Extract CHM content
HTTPSERVER = 2  # Act as standalone HTTP server
DUMPHTML = 3  # Dump CHM file as plain text
CHM2TXT = 4    # Convert CHM file into Single Text file
CHM2HTML = 5  # Convert CHM file into Single HTML file
CHM2PDF = 6    # Convert CHM file into PDF Document
#CHM2PS = 7    # Convert CHM file into PDF Document

# Special characters
COMMASPACE = ', '
LF = '\n'
CR = '\r'

# what config file to use - local or a system wide?
user_config = os.path.join(os.path.expanduser('~'), '.arch.conf')
if os.path.exists(user_config):
  config = user_config
else:
  config = '/etc/archmage/arch.conf'

# Miscellaneous auxiliary functions
def message(code=OK, msg=''):
  outfp = sys.stdout
  if code == ERROR:
    outfp = sys.stderr
  if msg:
    print >> outfp, msg

def file2dir(filename):
  """Convert file filename.chm to filename_html directory"""
  dirname = filename.rsplit('.', 1)[0] + '_' + 'html'
  return dirname

def output_format(mode):
  if mode == 'text':
    return CHM2TXT
  elif mode == 'html':
    return CHM2HTML
  elif mode == 'pdf':
    return CHM2PDF
#  elif mode == 'ps':
#    return CHM2PS
  else:
    sys.exit('Invalid output file format: %s' % mode)

def output_file(filename, mode):
  """Convert filename.chm to filename.output"""
  if mode == CHM2TXT:
    file_ext = 'txt'
  elif mode == CHM2HTML:
    file_ext = 'html'
  elif mode == CHM2PDF:
    file_ext = 'pdf'
#  elif mode == CHM2PS:
#    file_ext = 'ps'
  else:
    file_ext = 'output'
  output_filename = filename.rsplit('.', 1)[0] + '.' + file_ext
  return output_filename

# Our own listdir method :)
def listdir(dir):
  def f(res, dir, files):
    for e in files:
      d = '/'.join(dir.split('/')[1:])
      if d: d += '/'
      res.append(d + e)
  res = []
  os.path.walk(dir, f, res)
  return res
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.