Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Scheduling Scripts
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xx network
Scheduling Scripts
Commits
80c59a92
Commit
80c59a92
authored
Nov 23, 2021
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
improved upload script
parent
e9447cb3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
upload.py
+18
-11
18 additions, 11 deletions
upload.py
with
18 additions
and
11 deletions
upload.py
+
18
−
11
View file @
80c59a92
...
...
@@ -80,26 +80,25 @@ def upload(src_path, dst_path, s3_bucket, region,
log
.
error
(
"
Unable to upload {} to S3: {}
"
.
format
(
src_path
,
e
))
def
cmp_hash
(
curren
t_hash
,
file_
name
):
def
ge
t_hash
(
file_
path
):
"""
Obtain the hash of the file at the given path
:param current_hash:
:param file_name:
:return:
:param file_path: Path of the file to hash
:return: Hash of the file
"""
hasher
=
hashlib
.
md5
()
with
open
(
file_
name
,
'
rb
'
)
as
f
:
with
open
(
file_
path
,
'
rb
'
)
as
f
:
buf
=
f
.
read
()
hasher
.
update
(
buf
)
new_hash
=
hasher
.
hexdigest
()
log
.
debug
(
f
"
Current Hash:
{
current_hash
}
, New Hash:
{
new_hash
}
"
)
return
current_hash
==
new_hash
return
hasher
.
hexdigest
()
def
main
():
args
=
get_args
()
log
.
info
(
"
Running with configuration: {}
"
.
format
(
args
))
upload_frequency
=
60
s3_bucket_name
=
args
[
"
s3_bucket
"
]
s3_access_key_id
=
args
[
"
s3_access_key
"
]
s3_access_key_secret
=
args
[
"
s3_secret
"
]
...
...
@@ -107,13 +106,21 @@ def main():
remote_path
=
args
[
'
remote_path
'
]
local_path
=
os
.
path
.
expanduser
(
args
[
'
local_path
'
])
upload_frequency
=
60
# Wait for the file to exist
log
.
info
(
f
"
Waiting for
{
local_path
}
...
"
)
while
not
os
.
path
.
exists
(
local_path
):
time
.
sleep
(
upload_frequency
)
current_hash
=
""
while
True
:
if
os
.
path
.
exists
(
local_path
):
if
cmp_hash
(
current_hash
,
local_path
):
try
:
new_hash
=
get_hash
(
local_path
)
log
.
debug
(
f
"
Current Hash:
{
current_hash
}
, New Hash:
{
new_hash
}
"
)
if
current_hash
!=
new_hash
:
upload
(
local_path
,
remote_path
,
s3_bucket_name
,
s3_bucket_region
,
s3_access_key_id
,
s3_access_key_secret
)
except
Exception
as
e
:
log
.
error
(
f
"
Unhandled exception occurred:
{
e
}
"
,
exc_info
=
True
)
time
.
sleep
(
upload_frequency
)
...
...
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