Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
ale
djrandom-py
Commits
ae6e8ab9
Commit
ae6e8ab9
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
use a SQLite-backed database for seen hashes
parent
a8ef1672
Branches
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
client/djrandom_client/upload.py
+27
-4
27 additions, 4 deletions
client/djrandom_client/upload.py
with
27 additions
and
4 deletions
client/djrandom_client/upload.py
+
27
−
4
View file @
ae6e8ab9
...
...
@@ -6,6 +6,7 @@ import os
import
optparse
import
platform
import
socket
import
sqlite3
import
threading
import
time
import
urllib2
...
...
@@ -19,20 +20,42 @@ log = logging.getLogger(__name__)
class
FileDatabase
(
object
):
"""
SQLite-backed database of seen hashes.
"""
def
__init__
(
self
,
dbpath
=
None
):
if
not
dbpath
:
dbpath
=
os
.
path
.
join
(
os
.
getenv
(
'
HOME
'
),
'
.djrandom
'
)
self
.
db
=
anydbm
.
open
(
dbpath
,
'
c
'
,
0600
)
if
not
dbpath
.
endswith
(
'
.db
'
):
dbpath
+=
'
.db
'
is_new
=
not
os
.
path
.
exist
(
dbpath
)
self
.
conn
=
sqlite3
.
connect
(
dbpath
)
self
.
conn
.
text_factory
=
str
if
is_new
:
self
.
conn
.
execute
(
'
create table seen (sha1 text(40), stamp integer,
'
'
primary key (sha1))
'
)
self
.
conn
.
commit
()
def
close
(
self
):
self
.
db
.
close
()
self
.
conn
.
close
()
def
has
(
self
,
key
):
return
key
in
self
.
db
c
=
self
.
conn
.
cursor
()
row
=
c
.
execute
(
'
select stamp from seen where sha1 = ?
'
,
(
key
,)
).
fetchone
()
if
row
:
return
True
else
:
return
False
def
add
(
self
,
key
):
self
.
db
[
key
]
=
'
%i
'
%
time
.
time
()
c
=
self
.
conn
.
cursor
()
c
.
execute
(
'
insert or replace into seen (sha1, stamp) values (?, ?)
'
,
(
key
,
int
(
time
.
time
())))
c
.
commit
()
class
Uploader
(
object
):
...
...
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