src/Pure/Admin/build_easychair.scala
author wenzelm
Fri, 25 Nov 2022 14:44:22 +0100
changeset 76530 2bf13b30b98e
parent 76529 ded37aade88e
child 76546 88cecb9f1cdc
permissions -rw-r--r--
clarified signature; omit somewhat pointless test for "unzip" command;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/build_easychair.scala
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
     3
76479
8ac1d83301b5 tuned comments;
wenzelm
parents: 76398
diff changeset
     4
Build Isabelle component for Easychair LaTeX style.
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
     5
76398
fc35958d2e73 tuned comments;
wenzelm
parents: 76396
diff changeset
     6
See also https://easychair.org/publications/for_authors
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
     7
*/
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
     8
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
     9
package isabelle
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    10
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    11
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    12
object Build_Easychair {
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    13
  /* build easychair component */
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    14
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    15
  val default_url = "https://easychair.org/publications/easychair.zip"
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    16
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    17
  def build_easychair(
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    18
    download_url: String = default_url,
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    19
    target_dir: Path = Path.current,
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    20
    progress: Progress = new Progress
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    21
  ): Unit = {
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    22
    Isabelle_System.with_tmp_file("download", ext = "zip") { download_file =>
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    23
      Isabelle_System.with_tmp_dir("download") { download_dir =>
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    24
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    25
        /* download */
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    26
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    27
        Isabelle_System.download_file(download_url, download_file, progress = progress)
76530
2bf13b30b98e clarified signature;
wenzelm
parents: 76529
diff changeset
    28
        Isabelle_System.extract(download_file, download_dir)
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    29
76529
ded37aade88e clarified signature;
wenzelm
parents: 76518
diff changeset
    30
        val easychair_dir = File.get_dir(download_dir, title = download_url)
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    31
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    32
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    33
        /* component */
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    34
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    35
        val version =
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    36
          Library.try_unprefix("EasyChair", easychair_dir.file_name)
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    37
            .getOrElse("Failed to detect version from " + quote(easychair_dir.file_name))
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    38
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    39
        val component = "easychair-" + version
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76479
diff changeset
    40
        val component_dir =
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76479
diff changeset
    41
          Components.Directory.create(target_dir + Path.basic(component), progress = progress)
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    42
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76479
diff changeset
    43
        Isabelle_System.rm_tree(component_dir.path)
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76479
diff changeset
    44
        Isabelle_System.copy_dir(easychair_dir, component_dir.path)
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76479
diff changeset
    45
        Isabelle_System.make_directory(component_dir.etc)
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    46
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    47
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    48
        /* settings */
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    49
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76479
diff changeset
    50
        File.write(component_dir.settings,
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    51
          """# -*- shell-script -*- :mode=shellscript:
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    52
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    53
ISABELLE_EASYCHAIR_HOME="$COMPONENT"
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    54
""")
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    55
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    56
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    57
        /* README */
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    58
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76479
diff changeset
    59
        File.write(component_dir.README,
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    60
          """This is the Easychair style for authors from
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    61
""" + download_url + """
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    62
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    63
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    64
    Makarius
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    65
    """ + Date.Format.date(Date.now()) + "\n")
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    66
      }
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    67
    }
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    68
  }
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    69
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    70
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    71
  /* Isabelle tool wrapper */
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    72
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    73
  val isabelle_tool =
76479
8ac1d83301b5 tuned comments;
wenzelm
parents: 76398
diff changeset
    74
    Isabelle_Tool("build_easychair", "build component for Easychair LaTeX style",
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    75
      Scala_Project.here,
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    76
      { args =>
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    77
        var target_dir = Path.current
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    78
        var download_url = default_url
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    79
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    80
        val getopts = Getopts("""
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    81
Usage: isabelle build_easychair [OPTIONS]
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    82
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    83
  Options are:
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    84
    -D DIR       target directory (default ".")
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    85
    -U URL       download URL (default: """" + default_url + """")
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    86
76479
8ac1d83301b5 tuned comments;
wenzelm
parents: 76398
diff changeset
    87
  Build component for Easychair LaTeX style.
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    88
""",
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    89
          "D:" -> (arg => target_dir = Path.explode(arg)),
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    90
          "U:" -> (arg => download_url = arg))
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    91
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    92
        val more_args = getopts(args)
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    93
        if (more_args.nonEmpty) getopts.usage()
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    94
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    95
        val progress = new Console_Progress()
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    96
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    97
        build_easychair(download_url = download_url, target_dir = target_dir, progress = progress)
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    98
      })
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    99
}