Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
chipathlon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Holland Computing Center
chipathlon
Commits
192ab3ea
Commit
192ab3ea
authored
7 years ago
by
aknecht2
Browse files
Options
Downloads
Patches
Plain Diff
Fixed issues with circular dependncy in utils / db.py
parent
69ec65f8
No related branches found
No related tags found
1 merge request
!33
Resolve "MongoDB auth should be optional"
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
chipathlon/db.py
+14
-1
14 additions, 1 deletion
chipathlon/db.py
chipathlon/utils.py
+0
-17
0 additions, 17 deletions
chipathlon/utils.py
scripts/chip-job-download-gridfs
+8
-8
8 additions, 8 deletions
scripts/chip-job-download-gridfs
with
22 additions
and
26 deletions
chipathlon/db.py
+
14
−
1
View file @
192ab3ea
...
...
@@ -11,7 +11,20 @@ import chipathlon.conf
from
pprint
import
pprint
import
hashlib
from
chipathlon.utils
import
progress
import
bson
def
download_from_gridfs
(
host
,
gridfs_id
,
local_path
,
username
=
None
,
password
=
None
,
retries
=
3
,
overwrite
=
True
,
checkmd5
=
False
):
mdb
=
chipathlon
.
db
.
MongoDB
(
host
,
username
,
password
)
if
not
os
.
path
.
isfile
(
local_path
)
or
overwrite
:
for
i
in
range
(
0
,
retries
):
print
"
Attempt #%s, downloading file with ID
'
%s
'
to
'
%s
'"
%
(
i
+
1
,
gridfs_id
,
local_path
)
if
mdb
.
fetch_from_gridfs
(
bson
.
objectid
.
ObjectId
(
gridfs_id
),
localpath
,
checkmd5
):
return
True
else
:
print
"
Download attempt #%s from GridFS failed, retrying...
"
%
(
i
+
1
)
else
:
print
"
File already exists, skipping download.
\n
"
return
False
class
MongoDB
(
object
):
"""
...
...
This diff is collapsed.
Click to expand it.
chipathlon/utils.py
+
0
−
17
View file @
192ab3ea
...
...
@@ -3,8 +3,6 @@ import hashlib
import
urllib2
import
os
import
traceback
import
chipathlon.db
import
bson.objectid
def
progress
(
current
,
end
,
length
=
20
):
percent
=
float
(
current
)
/
end
...
...
@@ -50,21 +48,6 @@ def downloadFile(url, localpath, urltype="http://", retries=3, overwrite=True, c
print
"
File already exists, skipping download.
\n
"
return
def
downloadFromGridFS
(
hostname
,
username
,
password
,
gridfs_id
,
localpath
,
retries
=
3
,
overwrite
=
True
,
checkmd5
=
False
):
success
=
False
mdb
=
chipathlon
.
db
.
MongoDB
(
hostname
,
username
,
password
)
if
not
os
.
path
.
isfile
(
localpath
)
or
overwrite
:
for
i
in
range
(
0
,
retries
):
print
"
Attempt #%s, downloading file with ID
'
%s
'
to
'
%s
'"
%
(
i
+
1
,
gridfs_id
,
localpath
)
if
mdb
.
fetch_from_gridfs
(
bson
.
objectid
.
ObjectId
(
gridfs_id
),
localpath
,
checkmd5
):
success
=
True
break
else
:
print
"
Download attempt #%s from GridFS failed, retrying...
"
%
(
i
+
1
)
else
:
print
"
File already exists, skipping download.
\n
"
return
success
# http://pythoncentral.io/how-to-check-if-a-string-is-a-number-in-python-including-unicode/
def
is_number
(
s
):
try
:
...
...
This diff is collapsed.
Click to expand it.
scripts/chip-job-download-gridfs
+
8
−
8
View file @
192ab3ea
#!/usr/bin/env python
import
chipathlon.
utils
import
chipathlon.
db
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
"
Download target file from GridFS.
"
)
...
...
@@ -9,17 +9,17 @@ parser.add_argument("-p", "--password", dest="password", help="Database password
parser
.
add_argument
(
"
-i
"
,
"
--id
"
,
dest
=
"
gridfs_id
"
,
required
=
True
,
help
=
"
GridFS ID.
"
)
parser
.
add_argument
(
"
-d
"
,
"
--destination
"
,
dest
=
"
destination
"
,
required
=
True
,
help
=
"
Local path to file destination.
"
)
parser
.
add_argument
(
"
-r
"
,
"
--retries
"
,
dest
=
"
retries
"
,
default
=
3
,
type
=
int
,
help
=
"
Number of retries.
"
)
parser
.
add_argument
(
"
-n
"
,
"
--overwrite
"
,
dest
=
"
overwrite
"
,
default
=
True
,
action
=
"
store_false
"
,
help
=
"
Don
'
t overwrite local file if it exists.
"
)
parser
.
add_argument
(
"
-n
"
,
"
--
no-
overwrite
"
,
dest
=
"
overwrite
"
,
default
=
True
,
action
=
"
store_false
"
,
help
=
"
Don
'
t overwrite local file if it exists.
"
)
parser
.
add_argument
(
"
-c
"
,
"
--checkmd5
"
,
dest
=
"
checkmd5
"
,
action
=
"
store_true
"
,
help
=
"
Check md5 value of downloaded file against database value.
"
)
args
=
parser
.
parse_args
()
chipathlon
.
utils
.
download
F
rom
G
rid
FS
(
chipathlon
.
db
.
download
_f
rom
_g
rid
fs
(
args
.
host
,
args
.
username
,
args
.
password
,
args
.
gridfs_id
,
args
.
destination
,
args
.
retries
,
args
.
overwrite
,
args
.
checkmd5
username
=
args
.
username
,
password
=
args
.
password
,
retries
=
args
.
retries
,
overwrite
=
args
.
overwrite
,
checkmd5
=
args
.
checkmd5
)
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