Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
3pia
VISPA
VISPA web
Commits
7d4a979a
Commit
7d4a979a
authored
Jul 14, 2013
by
Marcel
Browse files
Fix uploads and badge titles.
parent
6872d046
Changes
6
Hide whitespace changes
Inline
Side-by-side
vispa/controller/filesystem.py
View file @
7d4a979a
...
...
@@ -25,7 +25,7 @@ class FSController(AbstractController):
return
data
def
handleDownload
(
self
,
path
,
wid
):
fs
=
self
.
get
(
'fs'
,
1
)
fs
=
self
.
get
(
'fs'
,
wid
)
if
not
fs
.
exists
(
path
,
'f'
):
raise
Exception
(
'The file
\'
%s
\'
does not exist'
%
path
)
data
=
fs
.
get_file_content
(
path
)
...
...
@@ -173,10 +173,11 @@ class FSAjaxController(AbstractController):
try
:
# extract the path
path
=
str
(
kwargs
[
'path'
])
path
=
self
.
expand
(
path
)
# prepare the parts
parts
=
kwargs
[
'files[]'
]
# force par
r
ts to be a list
# force parts to be a list
if
not
isinstance
(
parts
,
list
):
parts
=
[
parts
]
...
...
@@ -202,7 +203,7 @@ class FSAjaxController(AbstractController):
'The file extension
\'
%s
\'
is not supported by this server'
%
ext
)
# save the content using the fs
fs
.
save_file
_content
(
os
.
path
.
join
(
path
,
name
),
base64
.
b64encode
(
f
.
read
()),
force
=
True
)
fs
.
save_file
(
os
.
path
.
join
(
path
,
name
),
base64
.
b64encode
(
f
.
read
()),
binary
=
True
,
force
=
True
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
allow
(
methods
=
[
"POST"
])
...
...
vispa/extensions/codeeditor/__init__.py
View file @
7d4a979a
...
...
@@ -29,7 +29,7 @@ class CodeEditorController(AbstractController):
def
savecontent
(
self
,
path
,
content
):
try
:
fs
=
self
.
get
(
"fs"
)
success
=
fs
.
save_file
_content
(
str
(
path
),
content
)
success
=
fs
.
save_file
(
str
(
path
),
content
)
if
not
success
:
raise
Exception
(
"file already exists"
)
mtime
=
fs
.
get_mtime
(
path
)
...
...
vispa/extensions/file/static/js/base/base.js
View file @
7d4a979a
...
...
@@ -87,7 +87,7 @@ var FileBase = Class.extend({
dataType
:
'
json
'
,
done
:
function
(
e
,
data
)
{
msgObject
.
update
({
text
:
$
.
Helpers
.
strFormat
(
'
Upload done ({0})!
'
,
$
.
Helpers
.
bytesToString
(
data
.
loaded
)
)
,
text
:
'
Uploaded
'
+
$
.
Helpers
.
bytesToString
(
data
.
loaded
),
icon
:
'
ui-icon-check
'
});
self
.
updateView
();
...
...
vispa/extensions/file/static/js/browser/actions.js
View file @
7d4a979a
...
...
@@ -8,6 +8,5 @@ var FileBrowserActions = FileBaseActions.extend({
openFolder
:
function
(
data
)
{
this
.
owner
.
workflow
.
path
=
this
.
abspath
(
data
);
this
.
owner
.
updateView
();
Vispa
.
pathBar
.
setValue
(
this
.
owner
.
workflow
.
path
);
}
});
\ No newline at end of file
vispa/extensions/file/static/js/browser/browser.js
View file @
7d4a979a
...
...
@@ -20,5 +20,7 @@ var FileBrowser = FileBase.extend({
updateView
:
function
()
{
Vispa
.
extensionManager
.
updateUrl
(
this
.
instance
);
this
.
_super
();
Vispa
.
pathBar
.
setValue
(
this
.
workflow
.
path
);
$
(
this
.
instance
.
_viewData
.
badge
).
data
(
'
update
'
)(
this
.
workflow
.
path
,
this
.
workflow
.
path
);
}
});
\ No newline at end of file
vispa/remote/filesystem.py
View file @
7d4a979a
...
...
@@ -15,19 +15,21 @@ import base64
class
FileSystem
(
object
):
FILE_EXTENSIONS
=
[
"png"
,
"jpg"
,
"jpeg"
,
"bmp"
,
"ps"
,
"eps"
,
"pdf"
,
"txt"
,
"xml"
,
"py"
,
"c"
,
"cpp"
,
"root"
,
"pxlio"
]
BROWSER_EXTENSIONS
=
[
"png"
,
"jpg"
,
"jpeg"
,
"bmp"
,
"pdf"
]
ADDITIONAL_MIMES
=
{
"pxlio"
:
"text/plain"
,
"root"
:
"text/plain"
}
BROWSER_EXTENSIONS
=
[
"png"
,
"jpg"
,
"jpeg"
,
"bmp"
]
ADDITIONAL_MIMES
=
{
"pxlio"
:
"text/plain"
,
"root"
:
"text/plain"
}
def
__init__
(
self
):
# allowed extensions
self
.
allowed_extensions
=
FileSystem
.
FILE_EXTENSIONS
def
setup
(
self
,
basedir
=
None
):
if
basedir
==
None
:
basedir
=
os
.
path
.
expanduser
(
"~"
)
if
basedir
is
None
:
basedir
=
self
.
expand
(
'~/'
)
if
not
os
.
path
.
isdir
(
basedir
):
raise
Exception
(
"Basedir
("
+
str
(
basedir
)
+
")
does not exist!"
)
raise
Exception
(
"Basedir
'%s'
does not exist!"
%
basedir
)
# the basedir
self
.
basedir
=
os
.
path
.
join
(
basedir
,
".vispa"
)
if
os
.
path
.
isdir
(
self
.
basedir
):
...
...
@@ -37,6 +39,7 @@ class FileSystem(object):
return
"Basedir now exists"
def
get_mime_type
(
self
,
filepath
):
filepath
=
self
.
expand
(
filepath
)
mime
,
encoding
=
guess_type
(
filepath
)
if
mime
is
not
None
:
return
mime
...
...
@@ -46,6 +49,7 @@ class FileSystem(object):
return
None
def
check_file_extension
(
self
,
path
,
extensions
=
[]):
path
=
self
.
expand
(
path
)
if
(
len
(
extensions
)
==
0
):
return
True
for
elem
in
extensions
:
...
...
@@ -56,8 +60,7 @@ class FileSystem(object):
def
exists
(
self
,
path
,
type
=
None
):
# type may be 'f' or 'd'
if
path
:
path
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
path
))
path
=
self
.
expand
(
path
)
# path exists physically?
if
not
os
.
path
.
exists
(
path
):
return
None
...
...
@@ -72,7 +75,7 @@ class FileSystem(object):
def
get_file_list
(
self
,
path
,
deep
=
False
,
filter
=
[],
reverse
=
False
,
hide_hidden
=
True
,
encode_json
=
False
):
filelist
=
[]
path_expand
=
os
.
path
.
expanduser
(
os
.
path
.
expand
vars
(
path
)
)
path_expand
=
self
.
expand
(
path
)
try
:
for
elem
in
os
.
listdir
(
path_expand
):
# hide hidden files?
...
...
@@ -115,9 +118,10 @@ class FileSystem(object):
suggestions
=
[]
source
,
filter
=
None
,
None
# does the path exist?
if
os
.
path
.
exists
(
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
path
))):
path_expanded
=
self
.
expand
(
path
)
if
os
.
path
.
exists
(
path_expanded
):
# dir case
if
os
.
path
.
isdir
(
os
.
path
.
expand
user
(
os
.
path
.
expandvars
(
path
))
):
if
os
.
path
.
isdir
(
path
_
expand
ed
):
if
path
.
endswith
(
'/'
):
source
=
path
else
:
...
...
@@ -153,6 +157,7 @@ class FileSystem(object):
return
suggestions
if
not
encode_json
else
json
.
dumps
(
suggestions
)
def
cut_slashs
(
self
,
path
):
path
=
self
.
expand
(
path
)
path
=
path
[
1
:]
if
path
.
startswith
(
os
.
sep
)
else
path
if
path
==
""
:
return
path
...
...
@@ -160,8 +165,9 @@ class FileSystem(object):
return
path
def
create_folder
(
self
,
path
,
name
):
path
=
self
.
expand
(
path
)
# folder with the same name existent?
fullpath
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
os
.
path
.
join
(
path
,
name
)
))
fullpath
=
os
.
path
.
join
(
path
,
name
)
if
os
.
path
.
isdir
(
fullpath
):
raise
Exception
(
"Name already in use!"
)
try
:
...
...
@@ -171,8 +177,9 @@ class FileSystem(object):
raise
Exception
(
str
(
e
))
def
create_file
(
self
,
path
,
name
):
path
=
self
.
expand
(
path
)
# file with the same name existent?
fullpath
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
os
.
path
.
join
(
path
,
name
)
))
fullpath
=
os
.
path
.
join
(
path
,
name
)
if
os
.
path
.
exists
(
fullpath
):
raise
Exception
(
"Name already in use!"
)
try
:
...
...
@@ -181,45 +188,31 @@ class FileSystem(object):
except
Exception
as
e
:
raise
Exception
(
str
(
e
))
def
rename_folder
(
self
,
path
,
name
):
#
file or folder
if
not
os
.
path
.
isdir
(
path
):
raise
Exception
(
"Renaming file wi
th f
older function!"
)
def
rename_folder
(
self
,
path
,
name
,
force
=
False
):
#
TODO
pass
# os.renames(pa
th
,
f
ullpath
)
# folder with the same name existent?
path
=
path
if
not
path
.
endswith
(
os
.
sep
)
else
path
[:
-
1
]
fullpath
=
os
.
path
.
join
(
os
.
sep
.
join
(
path
.
split
(
os
.
sep
)[:
-
1
]),
name
)
if
os
.
path
.
exists
(
fullpath
):
raise
Exception
(
"Name already in use!"
)
os
.
renames
(
path
,
fullpath
)
def
rename_file
(
self
,
path
,
name
):
# file or folder
if
os
.
path
.
isdir
(
path
):
raise
Exception
(
"Renaming folder with file function!"
)
# file with the same name existent?
fullpath
=
os
.
path
.
join
(
os
.
sep
.
join
(
path
.
split
(
os
.
sep
)[:
-
1
]),
name
)
if
os
.
path
.
exists
(
fullpath
):
raise
Exception
(
"Name already in use!"
)
os
.
renames
(
path
,
fullpath
)
def
rename_file
(
self
,
path
,
name
,
force
=
False
):
# TODO
pass
# os.renames(path, fullpath)
def
remove
(
self
,
path
):
if
isinstance
(
path
,
list
):
for
p
in
path
:
self
.
remove
(
p
)
return
True
if
os
.
path
.
isdir
(
path
):
shutil
.
rmtree
(
path
)
else
:
os
.
remove
(
path
)
path
=
self
.
expand
(
path
)
if
os
.
path
.
isdir
(
path
):
shutil
.
rmtree
(
path
)
else
:
os
.
remove
(
path
)
def
compress
(
self
,
path
,
paths
,
name
):
# TODO
# paths has to be a list of strings
paths
=
paths
if
isinstance
(
paths
,
list
)
else
[
paths
]
paths
=
paths
if
isinstance
(
paths
,
(
list
,
tuple
)
)
else
[
paths
]
path
=
path
if
not
path
.
endswith
(
os
.
sep
)
else
path
[:
-
1
]
...
...
@@ -250,7 +243,8 @@ class FileSystem(object):
archive
.
close
()
def
paste
(
self
,
path
,
target
,
cut
):
if
isinstance
(
target
,
list
):
# TODO
if
isinstance
(
target
,
(
list
,
tuple
)):
for
p
in
target
:
self
.
paste
(
path
,
p
,
cut
)
return
True
...
...
@@ -269,32 +263,36 @@ class FileSystem(object):
if
cut
:
os
.
remove
(
target
)
def
save_file
_content
(
self
,
path
,
content
,
force
=
True
):
path
=
os
.
path
.
expandvars
(
os
.
path
.
expand
user
(
path
)
)
def
save_file
(
self
,
path
,
content
,
binary
=
False
,
force
=
True
):
path
=
self
.
expand
(
path
)
# check if file already exists
if
os
.
path
.
exists
(
path
)
and
not
force
:
return
False
out
=
open
(
path
,
"wb"
)
out
.
write
(
base64
.
b64decode
(
content
))
if
binary
:
content
=
base64
.
b64decode
(
content
)
out
.
write
(
content
)
out
.
close
()
return
True
def
get_file_content
(
self
,
path
):
path
=
os
.
path
.
expandvars
(
os
.
path
.
expand
user
(
path
)
)
path
=
self
.
expand
(
path
)
f
=
open
(
path
,
"r"
)
content
=
f
.
read
()
f
.
close
()
return
content
def
get_mtime
(
self
,
path
):
path
=
os
.
path
.
expandvars
(
os
.
path
.
expand
user
(
path
)
)
path
=
self
.
expand
(
path
)
return
os
.
path
.
getmtime
(
path
)
def
is_browser_file
(
self
,
path
):
path
=
self
.
expand
(
path
)
extension
=
path
.
split
(
"."
)[
-
1
]
return
extension
in
FileSystem
.
BROWSER_EXTENSIONS
def
handle_file_name_collision
(
self
,
name
,
path
):
# TODO
# collision?
files
=
os
.
listdir
(
path
)
if
name
not
in
files
:
...
...
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