示例#1
0
def main():
  from optparse import OptionParser

  usage = "Usage: scripts/phobos_doc.py VERSION PHOBOS_DIR [DESTINATION_DIR]"
  parser = OptionParser(usage=usage)
  #parser.add_option("--rev", dest="revision", metavar="REVISION", default=None,
    #type="int", help="set the repository REVISION to use in symbol links")
  parser.add_option("--zip", dest="zip", default=False, action="store_true",
    help="create a zip archive")

  (options, args) = parser.parse_args()

  if len(args) < 2:
    return parser.print_help()

  # Validate the version argument.
  m = re.match(r"((\d)\.(\d\d\d))", args[0])
  if not m:
    parser.error("invalid VERSION; format: /\d.\d\d\d/ E.g.: 1.123")
  matched = m.groups()
  # Extract the version strings.
  VERSION, V_MAJOR = matched[:2]
  V_MINOR = matched[2]
  D_VERSION  = V_MAJOR + ".0" # E.g.: 1.0 or 2.0

  # Path to the executable of dil.
  DIL_EXE   = Path("bin")/"dil"
  # The source code folder of Phobos.
  PHOBOS_SRC = Path(args[1])
  # Destination of doc files.
  DEST       = Path(max(args[2:3], 'phobosdoc'))
  # Destination of syntax highlighted source files.
  DEST.HTMLSRC = DEST/"htmlsrc"
  # Dil's data/ directory.
  DATA       = Path('data')
  # Temporary directory, deleted in the end.
  TMP        = DEST/"tmp"
  # The list of module files (with info) that have been processed.
  MODLIST    = TMP/"modules.txt"
  # List of files to ignore.
  IGNORE_LIST = ("phobos.d", "cast.d", "invariant.d", "switch.d", "unittest.d")
  IGNORE_LIST = [Path.sep+i for i in IGNORE_LIST] # Prepend with path separator.
  # The files to generate documentation for.
  FILES       = []

  if not PHOBOS_SRC.exists:
    print "The path '%s' doesn't exist." % PHOBOS_SRC
    return

  build_dil_if_inexistant(DIL_EXE)

  # Create the destination folders.
  DEST.makedirs()
  map(Path.mkdir, (DEST.HTMLSRC, TMP))

  # Begin processing.
  find_source_files(PHOBOS_SRC, FILES)
  # Filter out files in the internal/ folder and in the ignore list.
  FILES = [f for f in FILES if not any(map(f.endswith, IGNORE_LIST)) and \
                               not f.startswith(PHOBOS_SRC/"internal") ]
  FILES.sort() # Sort for index.

  modify_std_ddoc(PHOBOS_SRC/"std.ddoc", TMP/"phobos.ddoc", D_VERSION)
  write_overrides_ddoc(TMP/"overrides.ddoc")

  create_index_file(TMP/"index.d", PHOBOS_SRC, FILES)

  DOC_FILES = FILES + [PHOBOS_SRC/"phobos.d"] + \
              TMP//("index.d", "phobos.ddoc", "overrides.ddoc")
  versions = ["DDoc"]
  generate_docs(DIL_EXE, DEST, MODLIST, DOC_FILES, versions, options='-v -i')

  modlist = read_modules_list(MODLIST)

  for args in generate_shl_files2(DIL_EXE, DEST.HTMLSRC, modlist):
    print "hl %s > %s" % args;

  modify_phobos_html(DEST/"phobos.html", D_VERSION)

  copy_files(DATA, PHOBOS_SRC, DEST)

  TMP.rmtree()

  if options.zip:
    name, src = "Phobos_doc_"+VERSION, DEST
    cmd = "zip -q -9 -r %(name)s.zip %(src)s" % locals()
    print cmd
    os.system(cmd)
示例#2
0
def main():
    from optparse import OptionParser

    usage = "Usage: scripts/tango_doc.py TANGO_DIR [DESTINATION_DIR]"
    parser = OptionParser(usage=usage)
    parser.add_option(
        "--rev",
        dest="revision",
        metavar="REVISION",
        default=None,
        type="int",
        help="set the repository REVISION to use in symbol links",
    )
    parser.add_option("--zip", dest="zip", default=False, action="store_true", help="create a zip archive")

    (options, args) = parser.parse_args()

    if len(args) < 1:
        return parser.print_help()

    # Path to the executable of dil.
    DIL_EXE = Path("bin") / "dil"
    # The version of Tango we're dealing with.
    VERSION = ""
    # Root of the Tango source code (from SVN.)
    TANGO_DIR = Path(args[0])
    # The source code folder of Tango.
    TANGO_SRC = TANGO_DIR / "tango"
    # Destination of doc files.
    DEST = Path(args[1] if len(args) > 1 else "tangodoc")
    # The JavaScript folder.
    DEST.JS, DEST.CSS, DEST.IMG = DEST // ("js", "css", "img")
    # Destination of syntax highlighted source files.
    DEST.HTMLSRC = DEST / "htmlsrc"
    # Dil's data/ directory.
    DATA = Path("data")
    # Dil's fancy documentation format.
    KANDIL = Path("kandil")
    # Temporary directory, deleted in the end.
    TMP = DEST / "tmp"
    # Some DDoc macros for Tango.
    TANGO_DDOC = TMP / "tango.ddoc"
    # The list of module files (with info) that have been processed.
    MODLIST = TMP / "modules.txt"
    # The files to generate documentation for.
    FILES = []

    build_dil_if_inexistant(DIL_EXE)

    if not TANGO_DIR.exists:
        print "The path '%s' doesn't exist." % TANGO_DIR
        return

    VERSION = get_tango_version(TANGO_SRC / "core" / "Version.d")

    # Create directories.
    DEST.makedirs()
    map(Path.mkdir, (DEST.HTMLSRC, DEST.JS, DEST.CSS, DEST.IMG, TMP))

    find_source_files(TANGO_SRC, FILES)

    write_tango_ddoc(TANGO_DDOC, options.revision)
    DOC_FILES = [KANDIL / "kandil.ddoc", TANGO_DDOC] + FILES
    versions = ["Windows", "Tango", "DDoc"]
    generate_docs(DIL_EXE, DEST, MODLIST, DOC_FILES, versions, options="-v")

    modlist = read_modules_list(MODLIST)
    generate_modules_js(modlist, DEST.JS / "modules.js")

    for args in generate_shl_files2(DIL_EXE, DEST.HTMLSRC, modlist):
        print "hl %s > %s" % args

    copy_files(DATA, KANDIL, TANGO_DIR, DEST)
    download_jquery(DEST.JS / "jquery.js")

    TMP.rmtree()

    if options.zip:
        name, src = "Tango_doc_" + VERSION, DEST
        cmd = "zip -q -9 -r %(name)s.zip %(src)s" % locals()
        print cmd
        os.system(cmd)