src/Pure/Admin/component_easychair.scala
author Fabian Huch <huch@in.tum.de>
Thu, 06 Jun 2024 13:37:27 +0200
changeset 80260 ed9b1598d293
parent 77566 2a99fcb283ee
permissions -rw-r--r--
manage components of ci builds;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
77566
2a99fcb283ee renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents: 76548
diff changeset
     1
/*  Title:      Pure/Admin/component_easychair.scala
76396
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
77566
2a99fcb283ee renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents: 76548
diff changeset
    12
object Component_Easychair {
76396
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 =
76547
9fe5d8c70352 tuned signature;
wenzelm
parents: 76546
diff changeset
    41
          Components.Directory(target_dir + Path.basic(component)).create(progress = progress)
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    42
76546
88cecb9f1cdc proper unzip with strip option, within the JVM;
wenzelm
parents: 76530
diff changeset
    43
        Isabelle_System.extract(download_file, component_dir.path, strip = true)
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    44
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    45
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    46
        /* settings */
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    47
76548
0af64cc2eee9 tuned signature;
wenzelm
parents: 76547
diff changeset
    48
        component_dir.write_settings("""
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    49
ISABELLE_EASYCHAIR_HOME="$COMPONENT"
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    50
""")
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    51
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
        /* README */
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    54
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76479
diff changeset
    55
        File.write(component_dir.README,
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    56
          """This is the Easychair style for authors from
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    57
""" + download_url + """
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    58
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    59
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    60
    Makarius
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    61
    """ + Date.Format.date(Date.now()) + "\n")
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
  }
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    65
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
  /* Isabelle tool wrapper */
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
  val isabelle_tool =
77566
2a99fcb283ee renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents: 76548
diff changeset
    70
    Isabelle_Tool("component_easychair", "build component for Easychair LaTeX style",
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    71
      Scala_Project.here,
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    72
      { args =>
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    73
        var target_dir = Path.current
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    74
        var download_url = default_url
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    75
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    76
        val getopts = Getopts("""
77566
2a99fcb283ee renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents: 76548
diff changeset
    77
Usage: isabelle component_easychair [OPTIONS]
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    78
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    79
  Options are:
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    80
    -D DIR       target directory (default ".")
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    81
    -U URL       download URL (default: """" + default_url + """")
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    82
76479
8ac1d83301b5 tuned comments;
wenzelm
parents: 76398
diff changeset
    83
  Build component for Easychair LaTeX style.
76396
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    84
""",
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    85
          "D:" -> (arg => target_dir = Path.explode(arg)),
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    86
          "U:" -> (arg => download_url = arg))
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    87
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    88
        val more_args = getopts(args)
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    89
        if (more_args.nonEmpty) getopts.usage()
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    90
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    91
        val progress = new Console_Progress()
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    92
389d77e6be9f support for Easychair style with demo document;
wenzelm
parents:
diff changeset
    93
        build_easychair(download_url = download_url, target_dir = target_dir, progress = progress)
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
}