Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
into-cps-github-io
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Into-cps
github-into-cps
into-cps-github-io
Commits
d087f592
Commit
d087f592
authored
7 years ago
by
Kenneth Guldbrandt Lausdahl
Browse files
Options
Downloads
Patches
Plain Diff
added script to generate local usb version of a release from its url
parent
24a43d4d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
download/create-usb.py
+103
-0
103 additions, 0 deletions
download/create-usb.py
with
103 additions
and
0 deletions
download/create-usb.py
0 → 100755
+
103
−
0
View file @
d087f592
#!/usr/bin/env python
#
# Download script to generate a USB version of the complete download version
#
#
import
os
,
errno
import
urllib2
import
urlparse
,
urllib
import
hashlib
import
sys
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
'
USB Stick Download site creator.
'
)
parser
.
add_argument
(
'
--url
'
,
help
=
'
Specify URL of the download file
'
,
required
=
True
)
parser
.
add_argument
(
'
--skip
'
,
help
=
'
Skip download of the tool bundles
'
,
action
=
'
store_true
'
)
def
path2url
(
path
):
return
urlparse
.
urljoin
(
'
file:
'
,
urllib
.
pathname2url
(
path
))
def
human_size
(
bytes
,
units
=
[
'
bytes
'
,
'
KB
'
,
'
MB
'
,
'
GB
'
,
'
TB
'
,
'
PB
'
,
'
EB
'
]):
"""
Returns a human readable string reprentation of bytes
"""
return
str
(
bytes
)
+
units
.
pop
(
0
)
if
bytes
<
1024
else
human_size
(
bytes
>>
10
,
units
[
1
:])
def
downloadFile
(
url
,
outputPath
,
indent
):
u
=
urllib2
.
urlopen
(
url
)
meta
=
u
.
info
()
file_size
=
int
(
meta
.
getheaders
(
'
Content-Length
'
)[
0
])
# save downloaded file to TEMP directory
f
=
open
(
outputPath
,
'
wb
'
)
downloaded_bytes
=
0
block_size
=
1024
*
8
downloaded_bytes2
=
0
step
=
file_size
/
25
while
True
:
buffer
=
u
.
read
(
block_size
)
if
not
buffer
:
break
f
.
write
(
buffer
)
downloaded_bytes
+=
block_size
if
downloaded_bytes2
+
step
<
downloaded_bytes
:
print
"
%sDownloaded %s of %s
"
%
((
"
\t
"
*
indent
),
human_size
(
downloaded_bytes
),
human_size
(
file_size
))
downloaded_bytes2
=
downloaded_bytes
f
.
close
()
import
urllib
,
json
args
=
parser
.
parse_args
()
url
=
args
.
url
response
=
urllib
.
urlopen
(
url
)
data
=
json
.
loads
(
response
.
read
())
#print data
version
=
data
[
"
version
"
];
print
"
Processing version: %s
"
%
version
for
tool
in
data
[
"
tools
"
]:
print
"
\t
Processing tool %s
"
%
tool
for
p
in
data
[
"
tools
"
][
tool
][
"
platforms
"
]:
url
=
data
[
"
tools
"
][
tool
][
"
platforms
"
][
p
][
"
url
"
]
name
=
data
[
"
tools
"
][
tool
][
"
platforms
"
][
p
][
"
filename
"
]
md5sum
=
data
[
"
tools
"
][
tool
][
"
platforms
"
][
p
][
"
md5sum
"
]
print
"
\t\t
Platform: %s
"
%
p
directory
=
os
.
path
.
join
(
"
usb
"
,
version
,
tool
,
p
)
if
not
os
.
path
.
exists
(
directory
):
os
.
makedirs
(
directory
)
#urlShort = ('..'+url[75:] ) if len(url) > 75 else url
urlShort
=
url
[:
75
]
+
bool
(
url
[
75
:])
*
'
..
'
print
"
\t\t\t
Downloading %s from %s
"
%
(
name
,
urlShort
)
outFile
=
os
.
path
.
join
(
directory
,
name
)
print
"
\t\t\t\t
Output path: %s
"
%
outFile
md5
=
hashlib
.
md5
(
open
(
outFile
).
read
()).
hexdigest
()
if
os
.
path
.
exists
(
outFile
)
else
""
#print md5
if
md5
!=
md5sum
:
print
"
%sError CRC mismatch expected: %s got %s
"
%
((
"
\t
"
*
4
),
md5sum
,
md5
)
if
not
args
.
skip
:
downloadFile
(
url
,
outFile
,
4
)
else
:
print
"
%sCRC OK
"
%
(
"
\t
"
*
4
)
data
[
"
tools
"
][
tool
][
"
platforms
"
][
p
][
"
url
"
]
=
path2url
(
outFile
).
replace
(
"
file:///usb/
"
,
"
file:
"
)
md5
=
hashlib
.
md5
(
open
(
outFile
).
read
()).
hexdigest
()
if
os
.
path
.
exists
(
outFile
)
else
""
if
md5
!=
md5sum
:
print
"
%sCRC Error %s
"
%
((
"
\t
"
*
4
),
outFile
)
print
"
Writing modified version info for %s
"
%
version
with
open
(
os
.
path
.
join
(
"
usb
"
,
version
+
"
.json
"
),
'
w
'
)
as
outfile
:
json
.
dump
(
data
,
outfile
)
print
"
Writing top versions.json file
"
ov
=
{}
ov
[
version
]
=
version
+
"
.json
"
with
open
(
os
.
path
.
join
(
"
usb
"
,
"
versions.json
"
),
'
w
'
)
as
outfile
:
json
.
dump
(
ov
,
outfile
)
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