Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ale
ngv
Commits
6f54b1b7
Commit
6f54b1b7
authored
Sep 14, 2008
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sqlalchemy 0.5 fixes; simplify the Receiver class
parent
6a12952d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
53 deletions
+35
-53
ngv/uploadserver/model.py
ngv/uploadserver/model.py
+1
-1
ngv/uploadserver/uploadserver.py
ngv/uploadserver/uploadserver.py
+34
-52
No files found.
ngv/uploadserver/model.py
View file @
6f54b1b7
...
...
@@ -23,7 +23,7 @@ flags.define_string('upload_path', '-U', '--upload-path',
metadata
=
MetaData
()
Session
=
scoped_session
(
sessionmaker
(
autoflush
=
True
,
transactional
=
True
))
Session
=
scoped_session
(
sessionmaker
(
autoflush
=
True
,
autocommit
=
True
))
# Status:
...
...
ngv/uploadserver/uploadserver.py
View file @
6f54b1b7
...
...
@@ -44,15 +44,6 @@ def stream(file_object):
return
CustomFieldStorage
#class FileMonitor(object):
# def __init__(self, fp):
# self.fp = fp
# def read(self, n=-1):
# buf = self.fp.read(n)
# logging.info("Read %s" % buf)
# return buf
class
Generate
:
def
GET
(
self
):
m
=
md5
()
...
...
@@ -61,7 +52,7 @@ class Generate:
token
=
m
.
hexdigest
()
aobj
=
AsyncUpload
(
token
=
token
,
size
=
0
,
cur_size
=
0
,
exp_size
=
0
,
status
=
'N'
)
Session
.
save
(
aobj
)
Session
.
add
(
aobj
)
Session
.
commit
()
web
.
header
(
'Content-Type'
,
'application/json'
)
web
.
output
(
simplejson
.
dumps
(
token
))
...
...
@@ -92,56 +83,47 @@ class Receiver:
temp_path
=
temp_obj
.
path
()
rough_size
=
int
(
web
.
ctx
.
environ
.
get
(
'CONTENT_LENGTH'
,
'0'
))
temp_obj
.
exp_size
=
rough_size
Session
.
update
(
temp_obj
)
Session
.
add
(
temp_obj
)
Session
.
commit
()
logging
.
info
(
"upload: new AsyncUpload: %s"
%
token
)
try
:
class
Buffered
(
object
):
def
__init__
(
self
,
obj
):
self
.
obj
=
obj
self
.
last_sz
=
0
def
update
(
self
,
pos
):
self
.
obj
.
cur_size
=
pos
if
pos
-
self
.
last_sz
>
65535
:
Session
.
update
(
self
.
obj
)
Session
.
commit
()
self
.
last_sz
=
pos
buffobj
=
Buffered
(
temp_obj
)
def
callback
(
file
,
*
k
,
**
p
):
buffobj
.
update
(
file
.
tell
())
fp
=
ProgressFile
(
temp_path
,
'wb'
)
fp
.
set_callback
(
callback
)
custom_field_storage_class
=
stream
(
fp
)
custom_field_storage
=
custom_field_storage_class
(
environ
=
web
.
ctx
.
environ
,
keep_blank_values
=
1
,
fp
=
web
.
ctx
.
environ
[
'wsgi.input'
]
)
fp
.
close
()
final_size
=
os
.
path
.
getsize
(
temp_path
)
temp_obj
.
size
=
temp_obj
.
cur_size
=
final_size
temp_obj
.
status
=
'C'
Session
.
update
(
temp_obj
)
completed
=
True
logging
.
info
(
"%s: uploaded %d bytes"
%
(
token
,
final_size
))
finally
:
if
not
completed
:
logging
.
info
(
'upload of %s aborted, removing temporary file'
%
token
)
temp_obj
.
status
=
'E'
temp_obj
.
remove
()
Session
.
update
(
temp_obj
)
Session
.
commit
()
class
Buffered
(
object
):
def
__init__
(
self
,
obj
):
self
.
obj
=
obj
self
.
last_sz
=
0
def
update
(
self
,
pos
):
self
.
obj
.
cur_size
=
pos
if
pos
-
self
.
last_sz
>
16384
:
Session
.
add
(
self
.
obj
)
Session
.
commit
()
self
.
last_sz
=
pos
buffobj
=
Buffered
(
temp_obj
)
def
callback
(
file
,
*
k
,
**
p
):
buffobj
.
update
(
file
.
tell
())
fp
=
ProgressFile
(
temp_path
,
'wb'
)
fp
.
set_callback
(
callback
)
custom_field_storage_class
=
stream
(
fp
)
custom_field_storage
=
custom_field_storage_class
(
environ
=
web
.
ctx
.
environ
,
keep_blank_values
=
1
,
fp
=
web
.
ctx
.
environ
[
'wsgi.input'
]
)
fp
.
close
()
final_size
=
os
.
path
.
getsize
(
temp_path
)
logging
.
info
(
"%s: uploaded %d bytes"
%
(
token
,
final_size
))
temp_obj
.
exp_size
=
temp_obj
.
size
=
temp_obj
.
cur_size
=
final_size
temp_obj
.
status
=
'C'
Session
.
add
(
temp_obj
)
Session
.
commit
()
web
.
output
(
'OK'
)
urls
=
(
'/receiver/(.*)'
,
'Receiver'
,
'/ping/(.*)'
,
'Ping'
,
'/gen'
,
'Generate'
,
'/
_uploadserver/
receiver/(.*)'
,
'Receiver'
,
'/
_uploadserver/
ping/(.*)'
,
'Ping'
,
'/
_uploadserver/
gen'
,
'Generate'
,
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment