src/Pure/Admin/other_isabelle.scala
author wenzelm
Thu Oct 13 23:09:26 2016 +0200 (2016-10-13)
changeset 64201 c3edc64e219d
parent 64189 dfb63036c4f6
child 64304 96bc94c87a81
permissions -rw-r--r--
tuned;
     1 /*  Title:      Pure/Admin/other_isabelle.scala
     2     Author:     Makarius
     3 
     4 Manage other Isabelle distributions.
     5 */
     6 
     7 package isabelle
     8 
     9 
    10 private class Other_Isabelle(progress: Progress, isabelle_home: Path, isabelle_identifier: String)
    11 {
    12   other_isabelle =>
    13 
    14 
    15   /* static system */
    16 
    17   def bash(script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
    18     progress.bash(
    19       "export ISABELLE_IDENTIFIER=" + File.bash_string(isabelle_identifier) + "\n" + script,
    20       env = null, cwd = isabelle_home.file, redirect = redirect)
    21 
    22   def apply(cmdline: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
    23     bash("bin/isabelle " + cmdline, redirect, echo)
    24 
    25   def resolve_components(echo: Boolean): Unit =
    26     other_isabelle("components -a", redirect = true, echo = echo).check
    27 
    28   val isabelle_home_user: Path =
    29     Path.explode(other_isabelle("getenv -b ISABELLE_HOME_USER").check.out)
    30 
    31   val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
    32 
    33 
    34   /* init settings */
    35 
    36   def init_settings(components_base: String, nonfree: Boolean)
    37   {
    38     if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
    39       error("Cannot proceed with existing user settings file: " + etc_settings)
    40 
    41     Isabelle_System.mkdirs(etc_settings.dir)
    42     File.write(etc_settings,
    43       "# generated by Isabelle " + Date.now() + "\n" +
    44       "#-*- shell-script -*- :mode=shellscript:\n")
    45 
    46     val component_settings =
    47     {
    48       val components_base_path =
    49         if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
    50         else Path.explode(components_base).expand
    51 
    52       val catalogs =
    53         if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
    54 
    55       catalogs.map(catalog =>
    56         "init_components " + File.bash_path(components_base_path) +
    57           " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
    58     }
    59     File.append(etc_settings, "\n" + terminate_lines(component_settings))
    60   }
    61 }