Skip to content

Commit fff6dbf

Browse files
committed
Going back to "fs.cp", happier with "relative semantics" being playbook, absolute paths on filesystem. Corner case now is if you want to copy from the CWD you need to use absolute path.
1 parent d183d64 commit fff6dbf

File tree

13 files changed

+36
-35
lines changed

13 files changed

+36
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def restart_apache():
106106
pyinfra.systemd.service(service="apache2", restarted=True)
107107

108108
pyinfra.apt.packages(packages=["apache2"])
109-
fs.write(src="my-site.conf.j2", path="/etc/apache2/sites-available/my-site.conf").notify(restart_apache)
109+
fs.cp(src="my-site.conf.j2", path="/etc/apache2/sites-available/my-site.conf").notify(restart_apache)
110110
fs.ln(src="/etc/apache2/sites-available/my-site.conf", path="/etc/apache2/sites-enabled/", symbolic=True).notify(restart_apache)
111111
```
112112

docs/for_ansible_users.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ for item in [
3535
core.Item(src="foo.cfg.j2", path="/etc/foo/foo.cfg"),
3636
core.Item(src="bar.cfg.j2", path="/etc/foo/bar.cfg"),
3737
]:
38-
fs.write(**item)
38+
fs.cp(**item)
3939
# or:
40-
fs.write(src=item.src, path=item.dst)
40+
fs.cp(src=item.src, path=item.dst)
4141
# or:
42-
fs.write(src="{{item.src}}", path="{{item.dst}}")
42+
fs.cp(src="{{item.src}}", path="{{item.dst}}")
4343
```
4444

4545
The `**item` syntax applies the attributes from `item` as if they are arguments to the

docs/hacking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ information to uPlaybook about:
5050

5151
It is a tasks responsibility to determine if the arguments to it specify the existing
5252
system state, or if a change will be made. For example, the
53-
[fs.write()](tasks/fs.md#uplaybook.fs.write) task will check the destination file permissions,
53+
[fs.cp()](tasks/fs.md#uplaybook.fs.cp) task will check the destination file permissions,
5454
template the source file and compare it's hash with the existing file, and only apply the
5555
changes if they are meaningful.
5656

docs/playbooks/basics.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ modules, and writing several configuration files, these all may "notify" the
148148
def restart_apache():
149149
core.run("systemctl restart apache2")
150150
core.run("apt -y install apache2", creates="/etc/apache2").notify(restart_apache)
151-
fs.write(src="site1.conf.j2", path="/etc/apache2/sites-enabled/site1.conf").notify(restart_apache)
152-
fs.write(src="site2.conf.j2", path="/etc/apache2/sites-enabled/site2.conf").notify(restart_apache)
153-
fs.write(src="site3.conf.j2", path="/etc/apache2/sites-enabled/site3.conf").notify(restart_apache)
151+
fs.cp(src="site1.conf.j2", path="/etc/apache2/sites-enabled/site1.conf").notify(restart_apache)
152+
fs.cp(src="site2.conf.j2", path="/etc/apache2/sites-enabled/site2.conf").notify(restart_apache)
153+
fs.cp(src="site3.conf.j2", path="/etc/apache2/sites-enabled/site3.conf").notify(restart_apache)
154154
core.flush_handlers()
155155
# ensure apache is running
156156
run("wget -O /dev/null http://localhost/")
@@ -167,7 +167,7 @@ core.notify(handler)
167167
Handlers can be either a single handler function or a list of handlers:
168168

169169
```python
170-
fs.write(src="site.conf.j2", path="/etc/apache2/sites-available/site.conf").notify([
170+
fs.cp(src="site.conf.j2", path="/etc/apache2/sites-available/site.conf").notify([
171171
a2ensite,
172172
restart_apache
173173
])

docs/running.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ arguments it takes:
3939

4040
Run `up --up-docs module.task` to get help about a task:
4141

42-
$ up --up-docs fs.write
43-
# fs.write
42+
$ up --up-docs fs.cp
43+
# fs.cp
4444

4545
Copy the `src` file to `dst`, optionally templating the contents in `src`.
4646
[...]

docs/templating.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ in it, but if you do you have these options:
6969

7070
- Use a RawStr
7171
```
72-
fs.write(src="template.j2", path=core.RawStr("{{filename}}"))
72+
fs.cp(src="template.j2", path=core.RawStr("{{filename}}"))
7373
```
7474
- Put the value in a variable that is template expanded:
7575
```
7676
filename = "{{ my weird filename"
77-
fs.write(src="template.j2", path="{{filename}}")
77+
fs.cp(src="template.j2", path="{{filename}}")
7878
```
7979
- Use the "raw" Jinja2 tag:
8080
```
81-
fs.write(src="template.j2", path="{{raw}}{{filename}}{{endraw}}")
81+
fs.cp(src="template.j2", path="{{raw}}{{filename}}{{endraw}}")
8282
```
8383
8484
## Files with cp()
8585
86-
The `src` file in `fs.write()` will be template expanded (if `template` argument is set to
86+
The `src` file in `fs.cp()` will be template expanded (if `template` argument is set to
8787
True, the default).
8888
8989
!!! For Ansible Users

docs/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ for module_name in ["proxy", "uwsgi"]:
214214
fs.ln(src="/etc/apache2/mods-available/{{ module_name }}.load",
215215
path="/etc/apache2/mods-enabled",
216216
symbolic=True).notify(restart_apache)
217-
fs.write(path="/etc/apache2/sites-available/my-website.conf").notify(restart_apache)
217+
fs.cp(path="/etc/apache2/sites-available/my-website.conf").notify(restart_apache)
218218
fs.ln(src="/etc/apache2/sites-available/my-website.conf",
219219
path="/etc/apache2/sites-enabled",
220220
symbolic=True).notify(restart_apache)
@@ -226,7 +226,7 @@ Also write the file "my-website/my-website.conf.j2" with the following contents:
226226

227227
# My uwsgi website
228228

229-
Why do we call the file "my-website.conf.j2"? By default, `fs.write()` will: use the base
229+
Why do we call the file "my-website.conf.j2"? By default, `fs.cp()` will: use the base
230230
name of the resulting file as the source, and add ".j2" because by default it will do
231231
Jinja2 template expansion on the file contents. It can also Jinja2 expand file names as
232232
well, if doing a recursive write.

examples/new-uplaybook/playbook

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def git_init():
3939
core.run("git add .")
4040

4141
if ARGS.single_file:
42-
fs.write(src="playbook.j2", path=playbook_fs_name)
42+
fs.cp(src="playbook.j2", path=playbook_fs_name)
4343
else:
4444
fs.mkdir(path=ARGS.playbook_name).notify(git_init)
4545
with fs.cd(path=ARGS.playbook_name):
46-
fs.write(src="playbook.j2", path="playbook")
46+
fs.cp(src="playbook.j2", path="playbook")

tests/test_basics/basics.pb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from uplaybook import fs, core
55
fs.rm(path="testdir", recursive=True)
66
fs.mkdir(path="testdir")
77
with fs.cd(path="testdir"):
8-
fs.write(path="testfile")
8+
fs.cp(path="testfile")
99
assert fs.exists("testfile")
1010

1111
core.run(command="date")

tests/test_basics/notify.pb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fs.rm(path="testdir", recursive=True)
77
fs.mkdir(path="testdir")
88

99
core.notify(lambda: fs.rm(path="testdir", recursive=True))
10-
fs.write(path="testdir/testfile")
10+
fs.cp(path="testdir/testfile")
1111
assert fs.exists("testdir/testfile")
1212
core.flush_handlers()
1313
assert not fs.exists("testdir/testfile")

0 commit comments

Comments
 (0)