author | wenzelm |
Sat, 08 Apr 2023 16:37:54 +0200 | |
changeset 77783 | fb61887c069a |
parent 77518 | fda4da0f80f4 |
child 77784 | 4046731cfa6c |
permissions | -rw-r--r-- |
75555
197a5b3a1ea2
promote "isabelle sync" to regular user-space tool, with proper documentation;
wenzelm
parents:
75553
diff
changeset
|
1 |
/* Title: Pure/Tools/sync.scala |
75481 | 2 |
Author: Makarius |
3 |
||
4 |
Synchronize Isabelle + AFP repositories. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
75549 | 10 |
object Sync { |
75552
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
11 |
/* session images */ |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
12 |
|
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
13 |
def find_images(options: Options, session_images: List[String], |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
14 |
dirs: List[Path] = Nil |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
15 |
): List[String] = { |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
16 |
if (session_images.isEmpty) Nil |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
17 |
else { |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
18 |
val store = Sessions.store(options) |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
19 |
val sessions_structure = Sessions.load_structure(options, dirs = dirs) |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
20 |
sessions_structure.build_requirements(session_images).flatMap { session => |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
21 |
val heap = |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
22 |
store.find_heap(session).map(_.expand).map(path => |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
23 |
File.standard_path(path.dir.dir) + "/./" + path.dir.file_name + "/" + path.file_name) |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
24 |
val db = |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
25 |
store.find_database(session).map(_.expand).map(path => |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
26 |
File.standard_path(path.dir.dir.dir) + "/./" + path.dir.dir.file_name + "/" + |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
27 |
path.dir.file_name + "/" + path.file_name) |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
28 |
heap.toList ::: db.toList |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
29 |
} |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
30 |
} |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
31 |
} |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
32 |
|
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
33 |
|
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
34 |
/* sync */ |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
35 |
|
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
36 |
def sync(options: Options, context: Rsync.Context, target: Path, |
75487 | 37 |
thorough: Boolean = false, |
75553 | 38 |
purge_heaps: Boolean = false, |
75552
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
39 |
session_images: List[String] = Nil, |
75492 | 40 |
preserve_jars: Boolean = false, |
75481 | 41 |
dry_run: Boolean = false, |
42 |
rev: String = "", |
|
43 |
afp_root: Option[Path] = None, |
|
44 |
afp_rev: String = "" |
|
45 |
): Unit = { |
|
77517 | 46 |
val progress = context.progress |
47 |
||
75506 | 48 |
val hg = Mercurial.self_repository() |
75481 | 49 |
val afp_hg = afp_root.map(Mercurial.repository(_)) |
50 |
||
75492 | 51 |
val more_filter = if (preserve_jars) List("include *.jar", "protect *.jar") else Nil |
52 |
||
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
53 |
def sync(hg: Mercurial.Repository, dest: Path, r: String, |
75511 | 54 |
contents: List[File.Content] = Nil, filter: List[String] = Nil |
55 |
): Unit = { |
|
77518
fda4da0f80f4
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77517
diff
changeset
|
56 |
hg.sync(context, dest, rev = r, thorough = thorough, dry_run = dry_run, |
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
57 |
contents = contents, filter = filter ::: more_filter) |
75511 | 58 |
} |
75481 | 59 |
|
77518
fda4da0f80f4
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77517
diff
changeset
|
60 |
progress.echo("\n* Isabelle repository:", verbose = true) |
75553 | 61 |
val filter_heaps = if (purge_heaps) Nil else List("protect /heaps", "protect /heaps/**") |
75511 | 62 |
sync(hg, target, rev, |
75824 | 63 |
contents = List(File.content(Path.explode("etc/ISABELLE_ID"), hg.id(rev = rev))), |
75553 | 64 |
filter = filter_heaps ::: List("protect /AFP")) |
75481 | 65 |
|
66 |
for (hg <- afp_hg) { |
|
77518
fda4da0f80f4
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77517
diff
changeset
|
67 |
progress.echo("\n* AFP repository:", verbose = true) |
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
68 |
sync(hg, target + Path.explode("AFP"), afp_rev) |
75481 | 69 |
} |
75552
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
70 |
|
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
71 |
val images = |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
72 |
find_images(options, session_images, |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
73 |
dirs = afp_root.map(_ + Path.explode("thys")).toList) |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
74 |
if (images.nonEmpty) { |
77518
fda4da0f80f4
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77517
diff
changeset
|
75 |
progress.echo("\n* Session images:", verbose = true) |
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
76 |
val heaps = context.target(target + Path.explode("heaps")) + "/" |
77518
fda4da0f80f4
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77517
diff
changeset
|
77 |
Rsync.exec(context, thorough = thorough, dry_run = dry_run, |
76617 | 78 |
args = List("--relative", "--") ::: images ::: List(heaps)).check |
75552
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
79 |
} |
75481 | 80 |
} |
81 |
||
82 |
val isabelle_tool = |
|
75549 | 83 |
Isabelle_Tool("sync", "synchronize Isabelle + AFP repositories", |
75481 | 84 |
Scala_Project.here, { args => |
85 |
var afp_root: Option[Path] = None |
|
75553 | 86 |
var purge_heaps = false |
75552
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
87 |
var session_images = List.empty[String] |
75492 | 88 |
var preserve_jars = false |
75536
7cdeed5dc96d
more robust treatment of rsync on macOS (see also 96fb1f9a4042);
wenzelm
parents:
75525
diff
changeset
|
89 |
var protect_args = false |
75487 | 90 |
var thorough = false |
75481 | 91 |
var afp_rev = "" |
92 |
var dry_run = false |
|
76136
1bb677cceea4
let rsync re-use ssh connection via control path;
wenzelm
parents:
76134
diff
changeset
|
93 |
var ssh_port = 0 |
75481 | 94 |
var rev = "" |
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
95 |
var ssh_host = "" |
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
96 |
var ssh_user = "" |
75481 | 97 |
var verbose = false |
98 |
||
99 |
val getopts = Getopts(""" |
|
75549 | 100 |
Usage: isabelle sync [OPTIONS] TARGET |
75481 | 101 |
|
102 |
Options are: |
|
75497 | 103 |
-A ROOT include AFP with given root directory (":" for """ + AFP.BASE.implode + """) |
75553 | 104 |
-H purge heaps directory on target |
75552
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
105 |
-I NAME include session heap image and build database |
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
106 |
(based on accidental local state) |
75492 | 107 |
-J preserve *.jar files |
76134 | 108 |
-P protect spaces in target file names: more robust, less portable |
75493 | 109 |
-T thorough treatment of file content and directory times |
75481 | 110 |
-a REV explicit AFP revision (default: state of working directory) |
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
111 |
-s HOST SSH host name for remote target (default: local) |
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
112 |
-u USER explicit SSH user name |
75481 | 113 |
-n no changes: dry-run |
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
114 |
-p PORT explicit SSH port |
75481 | 115 |
-r REV explicit revision (default: state of working directory) |
116 |
-v verbose |
|
117 |
||
75555
197a5b3a1ea2
promote "isabelle sync" to regular user-space tool, with proper documentation;
wenzelm
parents:
75553
diff
changeset
|
118 |
Synchronize Isabelle + AFP repositories, based on "isabelle hg_sync". |
75481 | 119 |
""", |
75497 | 120 |
"A:" -> (arg => afp_root = Some(if (arg == ":") AFP.BASE else Path.explode(arg))), |
75553 | 121 |
"H" -> (_ => purge_heaps = true), |
75552
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
122 |
"I:" -> (arg => session_images = session_images ::: List(arg)), |
75492 | 123 |
"J" -> (_ => preserve_jars = true), |
76134 | 124 |
"P" -> (_ => protect_args = true), |
75487 | 125 |
"T" -> (_ => thorough = true), |
75481 | 126 |
"a:" -> (arg => afp_rev = arg), |
127 |
"n" -> (_ => dry_run = true), |
|
76136
1bb677cceea4
let rsync re-use ssh connection via control path;
wenzelm
parents:
76134
diff
changeset
|
128 |
"p:" -> (arg => ssh_port = Value.Int.parse(arg)), |
75481 | 129 |
"r:" -> (arg => rev = arg), |
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
130 |
"s:" -> (arg => ssh_host = arg), |
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
131 |
"u:" -> (arg => ssh_user = arg), |
75481 | 132 |
"v" -> (_ => verbose = true)) |
133 |
||
134 |
val more_args = getopts(args) |
|
135 |
val target = |
|
136 |
more_args match { |
|
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
137 |
case List(target) => Path.explode(target) |
75481 | 138 |
case _ => getopts.usage() |
139 |
} |
|
140 |
||
75552
4aa3da02fd4d
sync session images, based on accidental local state;
wenzelm
parents:
75549
diff
changeset
|
141 |
val options = Options.init() |
77518
fda4da0f80f4
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77517
diff
changeset
|
142 |
val progress = new Console_Progress(verbose = verbose) |
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
143 |
|
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
144 |
using(SSH.open_system(options, host = ssh_host, port = ssh_port, user = ssh_user)) { ssh => |
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
145 |
val context = Rsync.Context(progress, ssh = ssh, protect_args = protect_args) |
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
146 |
sync(options, context, target, thorough = thorough, purge_heaps = purge_heaps, |
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
147 |
session_images = session_images, preserve_jars = preserve_jars, dry_run = dry_run, |
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
148 |
rev = rev, afp_root = afp_root, afp_rev = afp_rev) |
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
149 |
} |
75481 | 150 |
} |
151 |
) |
|
152 |
} |