Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
workspaces
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
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ssa
workspaces
Merge requests
!176
Delivery rework
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Delivery rework
delivery-rework
into
main
Overview
10
Commits
5
Pipelines
4
Changes
4
7 unresolved threads
Hide all comments
Merged
Daniel Lyons
requested to merge
delivery-rework
into
main
3 years ago
Overview
10
Commits
5
Pipelines
4
Changes
4
7 unresolved threads
Hide all comments
Expand
Clean up destination code and add some functionality
Split the destinations into separate files
New DestinationTempFile for writing tempfiles into the destination which eventually get added
All of the close() methods are now streaming
Implemented ChecksumDecorator, so we get a SHA1SUMS file
Implemented FetchFile decorator, so we get a rudimentary fetch-all.sh script
Configured Docker and delivery for local development to have a separate volume mount for serving files
0
0
Merge request reports
Viewing commit
74ebed80
Show latest version
4 files
+
29
−
9
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
74ebed80
Document a few things, break out the subdirectory decorator even though it isn't used currently
· 74ebed80
Daniel Lyons
authored
3 years ago
apps/cli/executables/delivery/delivery/destinations/checksum.py
0 → 100644
+
58
−
0
Options
import
hashlib
import
pathlib
from
.interfaces
import
DestinationDecorator
,
Destination
class
ChecksumDecorator
(
DestinationDecorator
):
"""
Generate a SHA1SUMS file in the content root with an entry for every file that got delivered.
"""
def
__init__
(
self
,
underlying
:
Destination
):
super
().
__init__
(
underlying
)
self
.
sumsfile
=
underlying
.
create_file
(
"
SHA1SUMS
"
)
def
add_file
(
self
,
file
:
pathlib
.
Path
,
relative_path
:
str
):
# add the file to the archive the normal way
super
().
add_file
(
file
,
relative_path
)
# generate the hash and keep it
self
.
sumsfile
.
file
().
writelines
([
self
.
hash_file_line
(
file
,
relative_path
).
encode
(
"
utf8
"
)])
def
hash_file_line
(
self
,
file
:
pathlib
.
Path
,
relative_path
:
str
):
"""
Generate a line for the checksum file.
:param file: file to hash
:param relative_path: relative path to show in checksum file
:return: a line like
"
<hash> <relative_path>
"
"""
return
f
"
{
self
.
hash_file
(
file
)
}
{
relative_path
}
\n
"
@staticmethod
def
hash_file
(
file
:
pathlib
.
Path
):
Janet Goldstein
@jgoldste
·
3 years ago
should this be pydoc?
Please
register
or
sign in
to reply
"""
Hash the supplied file
:param file: file to hash
:return: string in SHA1SUMS format (hexdigest)
"""
# You would expect performance to be worse than calling a C program here, but in my own testing I found
# that the ensuing block is somewhat *faster* than calling "shasum" directly. I was able to hash a 1 GB
# random file in 1.2 seconds with the following code, versus 1.8 seconds with shasum. This is across about 10
# trials of each, with a warm cache in each case. So I would not refactor this code to shell out without
# doing more performance tests
#
# code courtesy of Stack Overflow: https://stackoverflow.com/a/59056796/812818
with
open
(
file
,
"
rb
"
)
as
f
:
file_hash
=
hashlib
.
sha1
()
while
chunk
:
=
f
.
read
(
8192
):
file_hash
.
update
(
chunk
)
return
file_hash
.
hexdigest
()
# to get a printable str instead of bytes
def
close
(
self
):
# first close the hash file
self
.
sumsfile
.
close
()
# now proceed
super
().
close
()
Loading
should this be pydoc?