Skip to content

Commit

Permalink
Add directory path to appfs openers
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Aug 19, 2017
1 parent 0b6f440 commit fb5e453
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.9]

### Changed

- MountFS and MultiFS now accept FS URLS
- Add openers for AppFS

## [2.0.8] - 2017-08-13

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


## [2.0.7] - 2017-08-06

### Fixes
Expand Down
17 changes: 13 additions & 4 deletions fs/opener/appfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .base import Opener
from .errors import OpenerError
from ..subfs import ClosingSubFS
from .. import appfs


Expand All @@ -31,9 +32,10 @@ class AppFSOpener(Opener):
}

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

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

fs_instance = fs_class(
app_fs = fs_class(
appname,
author=author,
version=version,
create=create
)
return fs_instance

app_fs = (
app_fs.opendir(path, factory=ClosingSubFS)
if delim
else app_fs
)

return app_fs

1 change: 1 addition & 0 deletions tests/test_appfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fs.appfs import UserDataFS



class TestAppFS(unittest.TestCase):
"""Test Application FS."""

Expand Down
12 changes: 11 additions & 1 deletion tests/test_opener.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import unittest
import pkg_resources

from fs import opener
from fs import open_fs, opener
from fs.osfs import OSFS
from fs.opener import registry, errors
from fs.memoryfs import MemoryFS
from fs.appfs import UserDataFS


class TestParse(unittest.TestCase):
Expand Down Expand Up @@ -223,3 +224,12 @@ def test_open_userdata_no_version(self):
self.assertEqual(app_fs.app_dirs.appname, 'fstest')
self.assertEqual(app_fs.app_dirs.appauthor, 'willmcgugan')
self.assertEqual(app_fs.app_dirs.version, None)

def test_user_data_opener(self):
user_data_fs = open_fs('userdata://fstest:willmcgugan:1.0')
self.assertIsInstance(user_data_fs, UserDataFS)
user_data_fs.makedir('foo', recreate=True)
user_data_fs.settext('foo/bar.txt', 'baz')
user_data_fs_foo_dir = open_fs('userdata://fstest:willmcgugan:1.0/foo/')
self.assertEqual(user_data_fs_foo_dir.gettext('bar.txt'), 'baz')

0 comments on commit fb5e453

Please sign in to comment.