Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tristan Cavelier
toolbox
Commits
54c439c2
Commit
54c439c2
authored
Jun 29, 2016
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cros-safe-copy: sync and sleep seem useless
parent
a969ec2e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
51 deletions
+15
-51
cros-safe-copy.py
cros-safe-copy.py
+15
-51
No files found.
cros-safe-copy.py
View file @
54c439c2
#!/usr/bin/env python2
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
"""
Usage: python cros-safe-copy.py SRC DST
[SLEEP]
Usage: python cros-safe-copy.py SRC DST
Where SRC is the source file path
Where SRC is the source file path
DST is the destination file path
DST is the destination file path
SLEEP is the time to wait between two copied chunk (in second)
Do a copy of flushed everytime chunks from SRC to DST. This is usefull if your
Do a copy of flushed everytime chunks from SRC to DST. This is usefull if your
`dd` command makes your machine rebooting. More, this script save the state
`dd` command makes your machine rebooting.
during copying so that even if the machine reboots, you can copy from where it
was stopped. (Be careful to run your script where CWD is persistent! Avoid /tmp
or ~/Downloads on Chromebooks!)
Example:
Example:
sudo python cros-safe-copy.py NayuOS.img /dev/sda
sudo python cros-safe-copy.py NayuOS.img /dev/sda
# savestate.json file is saved in CWD
"""
"""
import
sys
,
os
,
time
,
json
import
sys
,
os
KiB
=
1024
MiB
=
1024
*
KiB
input
=
sys
.
argv
[
1
]
input
=
sys
.
argv
[
1
]
output
=
sys
.
argv
[
2
]
output
=
sys
.
argv
[
2
]
sleep
=
int
(
sys
.
argv
[
3
])
if
len
(
sys
.
argv
)
>
3
else
0
bs
=
64
*
KiB
count
=
50
*
MiB
/
bs
def
saveState
(
d
):
skip
=
0
open
(
"savestate.json.lock"
,
"wx"
).
write
(
json
.
dumps
(
d
))
os
.
rename
(
"savestate.json.lock"
,
"savestate.json"
)
def
loadState
():
try
:
state
=
json
.
loads
(
open
(
"savestate.json"
).
read
())
print
"Using savestate.json"
return
state
except
IOError
:
print
"Creating savestate.json"
MiB
=
1024
*
1024
bs
=
65536
saveState
(
dict
(
input
=
input
,
output
=
output
,
bs
=
bs
,
count
=
50
*
MiB
/
bs
,
skip
=
0
,
seek
=
0
,
))
return
loadState
()
def
quote
(
args
):
def
quote
(
args
):
return
" "
.
join
([
"'%s'"
%
a
.
replace
(
"'"
,
"'
\
\
''"
)
for
a
in
args
])
return
" "
.
join
([
"'%s'"
%
a
.
replace
(
"'"
,
"'
\
\
''"
)
for
a
in
args
])
state
=
loadState
()
while
skip
*
bs
<
os
.
stat
(
input
).
st_size
:
assert
state
[
"input"
]
==
input
assert
state
[
"output"
]
==
output
while
state
[
"skip"
]
*
state
[
"bs"
]
<
os
.
stat
(
input
).
st_size
:
command
=
quote
([
command
=
quote
([
"dd"
,
"dd"
,
"bs=%d"
%
state
[
"bs"
]
,
"bs=%d"
%
bs
,
"count=%d"
%
state
[
"count"
]
,
"count=%d"
%
count
,
"seek=%d"
%
s
tate
[
"seek"
]
,
"seek=%d"
%
s
kip
,
"skip=%d"
%
s
tate
[
"skip"
]
,
"skip=%d"
%
s
kip
,
"if=%s"
%
input
,
"if=%s"
%
input
,
"of=%s"
%
output
,
"of=%s"
%
output
,
])
])
print
"$"
,
command
print
"$"
,
command
if
os
.
system
(
command
):
if
os
.
system
(
command
):
break
sys
.
exit
(
1
)
print
"$ sync"
skip
+=
count
if
os
.
system
(
"sync"
):
# seems not useful
break
state
[
"skip"
]
+=
state
[
"count"
]
state
[
"seek"
]
+=
state
[
"count"
]
saveState
(
state
)
if
sleep
>
0
:
print
"sleeping for %d second(s)"
%
sleep
time
.
sleep
(
sleep
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment