I really must insist I demand satisfaction haha
ST3: ExportHtml
@skuroda thanks for doing this. When I get off my butt tomorrow I am going to try this. Sounds like @castles is trying to keep you busy . I like his suggestion though.
gist.github.com/skuroda/4965913 … set-py-L21
Also, you could probably cut to the chase there, just piecing together an absolute path, checking if the file exists, rather than doing two os.listdir() calls.
Let’s pretend that I did that originally I did it in the _search_zip method. Also added a method to get package and asset name from absolute path. Updates on the Gist .
Edit: err half way. Woops.
Another thing, generally you wanna use try/finally when using open() zipfile.ZipFile() etc
Python has with
for that: with open(bla) as file_handle: file_handle.read()
def get_package_and_asset(path):
package = os.path.basename(os.path.dirname(path))
package = package.replace(".sublime-package", "")
asset = os.path.basename(path)
return (package, asset)
I want my money back! Oh wait, I didn’t pay any nor do I really care about windows absolute paths!
[quote=“castles_made_of_sand”]def get_package_and_asset(path):
package = os.path.basename(os.path.dirname(path))
package = package.replace(".sublime-package", "")
asset = os.path.basename(path)
return (package, asset)
I want my money back! Oh wait, I didn’t pay any nor do I really care about windows absolute paths![/quote]
Looks at my poor poor windows machine that I am forced to use for development
Nevermind I’m satiated haha
os.path.basename
That’s the one I was trying to think of the other day
[code]>>> import posixpath
import ntpath
ntpath.basename(“C:\fuck\fucker”)
‘fucker’os.path is posixpath
True
[/code]
Learn something every day
Yup I tested it after I posted. Also added the “with” statement. Hadn’t seen that before, though I still should have done the try catch stuff. Oh well though, this is why it’s good to share code.
Oh, wait, one more thing.
Will that helper handle nested assets? “Packages/Path/Subfolder/asset.pth”?
It will as soon as I fix it?
edit:
the “too” at the end was wrong and bothering me.
Haha, good answer
There’s also the bytes/unicode inconsistency on python 3 between zipfile open and normal open
Had to go take care of some other things, so that took longer than I wanted it to. Anyways, it should now handle nested assets. Also, everything is returned as bytes now.
I meant more this guy:
def get_package_and_asset(path):
package = os.path.basename(os.path.dirname(path))
package = package.replace(".sublime-package", "")
asset = os.path.basename(path)
return (package, asset)
That helper doesn’t handle nested paths too well.
Your get_package_asset function should have worked with nested files before, if I’m not mistaken
Ah I see. I will…get back on that. Ha. No I don’t think it would. I was just looking at the top level package directory, so anything nested would have been missed. I was…umm…testing you to make sure you saw the problem too? Yea let’s go with that
Unless you meant specifying the entire asset path, then yes it would have. In fact, maybe I should go back to that.
Edit:
So get_package_and_asset_name handles recursive files. I’ve added a parameter to get_package_asset to do the recursive search (defaults to false). I was thinking this may be useful if nested folders are allowed for settings. I think I’ve seen a post on this forum related to something like that.