add slash at end

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Martijn Offline
Team-XBMC
Posts: 10,260
Joined: Jul 2011
Reputation: 153
Location: Dawn of time
Post: #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)?

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
find quote
spiff Offline
Retired Developer
Posts: 12,386
Joined: Nov 2003
Post: #2
nope. but python has its own.
find quote
Martijn Offline
Team-XBMC
Posts: 10,260
Joined: Jul 2011
Reputation: 153
Location: Dawn of time
Post: #3
spiff Wrote:nope. but python has its own.

and could you by any chance enlighten me on that Rolleyes

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
find quote
giftie Online
Skilled Python Coder
Posts: 2,330
Joined: Mar 2010
Reputation: 53
Location: Calgary, Alberta
Post: #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.

[Image: e4f63e45ba34fe4695b3bb08eb2499d8e4ee484e...4c076g.jpg]
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager
fanart.tv


find quote
paddycarey Offline
Senior Member
Posts: 246
Joined: Sep 2009
Reputation: 8
Post: #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.
find quote
giftie Online
Skilled Python Coder
Posts: 2,330
Joined: Mar 2010
Reputation: 53
Location: Calgary, Alberta
Post: #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)

[Image: e4f63e45ba34fe4695b3bb08eb2499d8e4ee484e...4c076g.jpg]
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager
fanart.tv


(This post was last modified: 2011-11-25 03:17 by giftie.)
find quote
FrostBox Offline
Skilled Python Coder
Posts: 100
Joined: Nov 2005
Reputation: 6
Location: Quebec City
Post: #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
find quote
Martijn Offline
Team-XBMC
Posts: 10,260
Joined: Jul 2011
Reputation: 153
Location: Dawn of time
Post: #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

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
(This post was last modified: 2011-11-26 23:14 by Martijn.)
find quote
FrostBox Offline
Skilled Python Coder
Posts: 100
Joined: Nov 2005
Reputation: 6
Location: Quebec City
Post: #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
find quote
Martijn Offline
Team-XBMC
Posts: 10,260
Joined: Jul 2011
Reputation: 153
Location: Dawn of time
Post: #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/

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
(This post was last modified: 2011-11-27 00:10 by Martijn.)
find quote