Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
remote_tree_to_local_tars
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gary Ruben
remote_tree_to_local_tars
Commits
0b4176ab
Commit
0b4176ab
authored
6 years ago
by
Gary Ruben
Browse files
Options
Downloads
Patches
Plain Diff
documentation improvements
parent
d36a9b3f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
asci_to_vault.py
+12
-10
12 additions, 10 deletions
asci_to_vault.py
with
12 additions
and
10 deletions
asci_to_vault.py
+
12
−
10
View file @
0b4176ab
...
@@ -91,21 +91,24 @@ class Logger(object):
...
@@ -91,21 +91,24 @@ class Logger(object):
def
send_directory
(
node
):
def
send_directory
(
node
):
"""
Sends all files in the node.src directory to the node.dest directory
"""
Sends all files in the node.src directory to the node.dest directory
across an ssh connection using the cpio command to tar the files into a
across an ssh connection.
Different methods are used for single versus multiple files. For single
files, scp is used. For multiple files cpio is used to tar the files into a
single tarball. The destination tarball is named after the directories
single tarball. The destination tarball is named after the directories
trailing
the
SRC_PATH. Permissions are set to r_x for group and owner.
trailing SRC_PATH. Permissions are set to r_x for group and owner.
Args:
Args:
node: Node object
node: Node object
Contains source and destination director
ies
as follows:
Contains source and destination director
y information
as follows:
src: full path to a remote node
src: full path to a remote node
e.g. /data/13660a/asci/input
e.g. /data/13660a/asci/input
dest: full path to a destination node
dest: full path to a destination node
e.g. /home/grub0002/bapcxi/vault/imbl2018
e.g. /home/grub0002/bapcxi/vault/imbl2018
count: number of files at the remote node
"""
"""
# Check if there are any files in the node
# Check if there are any files in the node.
# add check to make sure connection is working
with
Connection
(
REMOTE_LOGIN
)
as
c
:
with
Connection
(
REMOTE_LOGIN
)
as
c
:
files
=
c
.
run
(
files
=
c
.
run
(
rf
"
cd
{
node
.
src
}
; find -maxdepth 1 -type f -printf
'
%f\n
'"
,
rf
"
cd
{
node
.
src
}
; find -maxdepth 1 -type f -printf
'
%f\n
'"
,
...
@@ -155,8 +158,7 @@ if __name__ == "__main__":
...
@@ -155,8 +158,7 @@ if __name__ == "__main__":
sys
.
stdout
=
Logger
()
# Log all stdout to a log file
sys
.
stdout
=
Logger
()
# Log all stdout to a log file
# A hacky way to restart an interrupted transfer is to set
# A hacky way to restart an interrupted transfer is to set
# READ_PICKLE_FILE = True above so that the transfer state is retrieved. By
# READ_PICKLE_FILE = True above so that the transfer state is retrieved.
# default the tree is built from scratch from the remote file system.
if
READ_PICKLE_FILE
:
if
READ_PICKLE_FILE
:
# Read the saved transfer state from the locally pickled tree object.
# Read the saved transfer state from the locally pickled tree object.
with
open
(
PICKLE_FILENAME
,
'
rb
'
)
as
f
:
with
open
(
PICKLE_FILENAME
,
'
rb
'
)
as
f
:
...
@@ -173,7 +175,7 @@ if __name__ == "__main__":
...
@@ -173,7 +175,7 @@ if __name__ == "__main__":
else
:
else
:
break
break
else
:
else
:
# Get the directory tree from remote server as a list
# Get the directory tree from
the
remote server as a list
.
with
Connection
(
REMOTE_LOGIN
)
as
c
:
with
Connection
(
REMOTE_LOGIN
)
as
c
:
result
=
c
.
run
(
f
'
find
{
SRC_PATH
}
-type d
'
)
result
=
c
.
run
(
f
'
find
{
SRC_PATH
}
-type d
'
)
remote_dirs
=
result
.
stdout
.
strip
().
splitlines
()
remote_dirs
=
result
.
stdout
.
strip
().
splitlines
()
...
@@ -185,14 +187,14 @@ if __name__ == "__main__":
...
@@ -185,14 +187,14 @@ if __name__ == "__main__":
dest
=
src
.
replace
(
SRC_PATH
,
DEST_PATH
)
dest
=
src
.
replace
(
SRC_PATH
,
DEST_PATH
)
tree
.
append
(
Node
(
src
,
dest
))
tree
.
append
(
Node
(
src
,
dest
))
# Transfer all directory tree nodes
# Transfer all directory tree nodes
.
for
i
,
node
in
enumerate
(
tree
):
for
i
,
node
in
enumerate
(
tree
):
if
not
node
.
processed
:
if
not
node
.
processed
:
pathlib
.
Path
(
node
.
dest
).
mkdir
(
parents
=
True
,
exist_ok
=
True
)
pathlib
.
Path
(
node
.
dest
).
mkdir
(
parents
=
True
,
exist_ok
=
True
)
os
.
chmod
(
node
.
dest
,
0o770
)
os
.
chmod
(
node
.
dest
,
0o770
)
send_directory
(
node
)
send_directory
(
node
)
# pickle the tree to keep a record of the processed state
# pickle the tree to keep a record of the processed state
.
with
open
(
PICKLE_FILENAME
,
'
wb
'
)
as
f
:
with
open
(
PICKLE_FILENAME
,
'
wb
'
)
as
f
:
pickle
.
dump
(
tree
,
f
)
pickle
.
dump
(
tree
,
f
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment