Skip to content

Commit fb5e453

Browse files
committed
Add directory path to appfs openers
1 parent 0b6f440 commit fb5e453

4 files changed

Lines changed: 32 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [2.0.9]
8+
9+
### Changed
10+
11+
- MountFS and MultiFS now accept FS URLS
12+
- Add openers for AppFS
13+
714
## [2.0.8] - 2017-08-13
815

916
### Added
@@ -12,7 +19,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1219
- FS.islink method
1320
- Info.is_link method
1421

15-
1622
## [2.0.7] - 2017-08-06
1723

1824
### Fixes

fs/opener/appfs.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from .base import Opener
99
from .errors import OpenerError
10+
from ..subfs import ClosingSubFS
1011
from .. import appfs
1112

1213

@@ -31,9 +32,10 @@ class AppFSOpener(Opener):
3132
}
3233

3334
def open_fs(self, fs_url, parse_result, writeable, create, cwd):
34-
fs_class = self._protocol_mapping[parse_result.protocol]
3535

36-
tokens = parse_result.resource.split(':', 3)
36+
fs_class = self._protocol_mapping[parse_result.protocol]
37+
resource, delim, path = parse_result.resource.partition('/')
38+
tokens = resource.split(':', 3)
3739
if len(tokens) == 2:
3840
appname, author = tokens
3941
version = None
@@ -45,11 +47,18 @@ def open_fs(self, fs_url, parse_result, writeable, create, cwd):
4547
'or <appname>:<author>:<version>'
4648
)
4749

48-
fs_instance = fs_class(
50+
app_fs = fs_class(
4951
appname,
5052
author=author,
5153
version=version,
5254
create=create
5355
)
54-
return fs_instance
56+
57+
app_fs = (
58+
app_fs.opendir(path, factory=ClosingSubFS)
59+
if delim
60+
else app_fs
61+
)
62+
63+
return app_fs
5564

tests/test_appfs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from fs.appfs import UserDataFS
88

99

10+
1011
class TestAppFS(unittest.TestCase):
1112
"""Test Application FS."""
1213

tests/test_opener.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import unittest
88
import pkg_resources
99

10-
from fs import opener
10+
from fs import open_fs, opener
1111
from fs.osfs import OSFS
1212
from fs.opener import registry, errors
1313
from fs.memoryfs import MemoryFS
14+
from fs.appfs import UserDataFS
1415

1516

1617
class TestParse(unittest.TestCase):
@@ -223,3 +224,12 @@ def test_open_userdata_no_version(self):
223224
self.assertEqual(app_fs.app_dirs.appname, 'fstest')
224225
self.assertEqual(app_fs.app_dirs.appauthor, 'willmcgugan')
225226
self.assertEqual(app_fs.app_dirs.version, None)
227+
228+
def test_user_data_opener(self):
229+
user_data_fs = open_fs('userdata://fstest:willmcgugan:1.0')
230+
self.assertIsInstance(user_data_fs, UserDataFS)
231+
user_data_fs.makedir('foo', recreate=True)
232+
user_data_fs.settext('foo/bar.txt', 'baz')
233+
user_data_fs_foo_dir = open_fs('userdata://fstest:willmcgugan:1.0/foo/')
234+
self.assertEqual(user_data_fs_foo_dir.gettext('bar.txt'), 'baz')
235+

0 commit comments

Comments
 (0)