add slash at end
#1
In this commit there is an internal util used for adding a slash at the end.

https://github.com/xbmc/xbmc/commit/9a5f...42262c00bc

Is this also available for add-ons (python)?
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#2
nope. but python has its own.
Reply
#3
spiff Wrote:nope. but python has its own.

and could you by any chance enlighten me on that Rolleyes
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#4
Machine-Sanctum Wrote:and could you by any chance enlighten me on that Rolleyes

you can always use, os.path.join( path, "" ) will add the proper file slash based on the OS.
Reply
#5
giftie Wrote:you can always use, os.path.join( path, "" ) will add the proper file slash based on the OS.

os.path.join works for the most part but where it falls down is when trying to work with smb:// or nfs:// paths on windows. It detects the OS as Windows and so uses \ when / would be correct for the path.

At the moment we have to test if the path contains :// and if it does set the separator to /.

Not pretty but it works.
Reply
#6
paddycarey Wrote:os.path.join works for the most part but where it falls down is when trying to work with smb:// or nfs:// paths on windows. It detects the OS as Windows and so uses \ when / would be correct for the path.

At the moment we have to test if the path contains :// and if it does set the separator to /.

Not pretty but it works.

I know python autocorrects the separators and I thought XBMC also does(I could be wrong, but the source code it does look like it does)

With that being said, it is easy to correct the slashes after an os.path.join().

Code:
if ( len( path ) > 1 and path[1] == ":" ) or ( len( path ) > 1 and path[0] == "\\" and path[1] == "\\" ):  # tests to see if is a DOS path or a windows share
    path.replace("/", "\\")
else:
    path.replace("\\", "/")

this is python version of what I found in the XBMC source code(URIUtils.cpp)
Reply
#7
Hi,

I use this in my all add-ons and work perfectly Nod

PHP Code:
# normalize the path (win32 support / as path separators) and make sure endswith by / 
fpath fpath.replace"\\""/" ).rstrip"/" ) + "/" 

print os.path.existsfpath "cache/test.txt" 
For my bad English, sorry. I am French Canadian.
Admin @ Passion-XBMC.org
Reply
#8
The problem is not in copy/deleting of files but in the caching of images and the way skins formulate the path. They always use '/' at the end of a path. So this will present a problem with win32 folder structures because the last slash of a movie path must be a '/' (and some skinners even create a '//'at the end).
So this path:
Code:
Z:\Films\Algemeen\Batman Begins (2005)
must become:
Code:
Z:\Films\Algemeen\Batman Begins (2005)/fanart.jpg
and sometimes:
Z:\Films\Algemeen\Batman Begins (2005)\fanart.jpg
and
Z:\Films\Algemeen\Batman Begins (2005)\extrafanart\ (multiple images)
See the problem here.

or some one must know an easier way to overcome the caching problem like discussed in:
http://forum.xbmc.org/showthread.php?tid=104857
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#9
Maybe with this

http://passion-xbmc.org/gros_fichiers/XB...lidatePath
PHP Code:
validatePath(...)
validatePath(path) -- Returns the validated path.
 
path           string or unicode Path to format
 
*NoteOnly useful if you are coding for both Linux and Windows/Xbox for fixing slash problems.
       
e.gCorrects 'Z://something' -> 'Z:\something'
 
example:
  - 
fpath xbmc.validatePath(somepath
Or see os.path.normpath(fpath) http://docs.python.org/release/2.5/lib/m....path.html
For my bad English, sorry. I am French Canadian.
Admin @ Passion-XBMC.org
Reply
#10
FrostBox Wrote:Maybe with this
....
Yeah I also tried that.

The real problem is that skinners cannot always have a universal way of using paths and they are not all doing it the same way.
So at the moment we have to anticipate that to replace the cached version of an image with a new one. Or else it won't be visible at once.
Did find something although i'm not really sure what it does:
http://passion-xbmc.org/addons/?Page=Vie...mageCacher
and
http://mirrors.xbmc.org/addons/eden-pre/...gin.cache/
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply

Logout Mark Read Team Forum Stats Members Help
add slash at end0