FileProvider module implementation with Django
Review Request #6806 — Created Jan. 18, 2015 and updated
The FileProvider module allows users to select files from their online file storage providers and choose which files to upload to ReviewBoard for file attachments. This module consists of the following files
reviewboard/fileproviders/model.py
: the Django model for representing file provider accounts for different users and file providersreviewboard/fileproviders/fileprovider.py
: the abstract FileProvider object to interact with the file providers.reviewboard/fileproviders/tree.py
: contains a base Node object, which can be used to represent files and directories found in the online file providers.reviewboard/fileproviders/errors.py
: contains error objects for the FileProvider framework
Anyone who wishes to support a particular file provider can do so by taking creating a derived class from FileProvider
and implement the object's methods as neccessary, as well as creating an entry point for the object under reviewboard.file_providers
Test cases for functions and some object method in
reviewboard/fileproviders/tests.py
Description | From | Last Updated |
---|---|---|
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 5 E265 block comment should start with '# ' |
reviewbot | |
Col: 5 E265 block comment should start with '# ' |
reviewbot | |
Col: 5 E303 too many blank lines (2) |
reviewbot | |
undefined name 'webapi_request_fields' |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
'webapi_response_errors' imported but unused |
reviewbot | |
Col: 5 E265 block comment should start with '# ' |
reviewbot | |
Col: 5 E303 too many blank lines (2) |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
I wouldn't name names. I would just say "An interface to a service that provides online file storage." |
chipx86 | |
"FileProvider" |
chipx86 | |
This doesn't really say what this is about. Think of the text from an end-user's perspective. What do they want … |
chipx86 | |
No blank line here. |
chipx86 | |
Are you sure you want to be setting the class variable like this? The only way to read/write it is … |
TB tbelaire | |
The """ should be on the first line when there's just a summary. |
chipx86 | |
Summaries can never wrap. They must be on one line, and the line length cannot exceed 79 characters. |
chipx86 | |
When possible, use single quotes instead of double quotes. We should also rename this function, since list is a reserved … |
chipx86 | |
Perhaps this is supposed to be name from above? |
TB tbelaire | |
Blank line between these. Imports are always in 3 sections (excluding the __future__ imports): Python standard library imports. Third-party modules … |
chipx86 | |
I know older code does this, but newer code can use @cached_property and not have to worry about the hasattr … |
chipx86 | |
Col: 5 E303 too many blank lines (2) |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 33 W292 no newline at end of file |
reviewbot | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
Col: 22 W292 no newline at end of file |
reviewbot | |
Col: 44 W292 no newline at end of file |
reviewbot | |
Col: 80 E501 line too long (82 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (80 > 79 characters) |
reviewbot | |
Col: 62 E231 missing whitespace after ',' |
reviewbot | |
Col: 5 E303 too many blank lines (2) |
reviewbot | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
'json_dump' imported but unused |
reviewbot | |
Col: 5 E303 too many blank lines (2) |
reviewbot | |
Col: 5 E303 too many blank lines (2) |
reviewbot | |
Col: 5 E303 too many blank lines (2) |
reviewbot | |
Col: 25 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 80 E501 line too long (89 > 79 characters) |
reviewbot | |
'User' imported but unused |
reviewbot | |
'get_object_or_none' imported but unused |
reviewbot | |
'fp_content_item_mimetype' imported but unused |
reviewbot | |
'ExtraDataItemMixin' imported but unused |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 80 E501 line too long (89 > 79 characters) |
reviewbot | |
We use single quote strings. |
brennie | |
How about authenticate? |
brennie | |
No blank line here. |
brennie | |
Likewise, how about deauthenticate? |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
This should be on the previous line. |
brennie | |
Blank line between these. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
Blank line between these. |
brennie | |
Blank line between these. |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
Blank line between these. |
brennie | |
Blank line between these. |
brennie | |
There should probably be a more specific exception for this (and elsewhere you're raising KeyError). Perhaps something along the lines … |
brennie | |
No blank line here. |
brennie | |
No blank line here. |
brennie | |
Blank line between these. |
brennie | |
Blank line between these. |
brennie | |
Since this is a JSON blob, this should have a dict type. |
brennie | |
Since this is a JSON field, this should have a dict type. |
brennie | |
Blank line between these. |
brennie | |
Wrap these in parenthesis to avoid using a backslash. |
brennie | |
We don't use the Python ternary. Instead use a regular if-else or data = {} if credentials: data = json_load(credentials) |
brennie | |
We should return what the invalid form data is (e.g., { 'reason': 'The credentials supplied were not parsable.' }). |
brennie | |
Add some documentation that describes what the resource does in broad terms. Documentation that is added to API resources will … |
brennie | |
There should be an added_in field that describes the Review Board version the API resource was added in. This should … |
brennie | |
Use double backticks for things marked as code in restructured text. Here and elsewhere. |
brennie | |
It should read like `... or folder, e.g., ... |
brennie | |
This should be on the previous line. |
brennie | |
No blank line here. |
brennie | |
Are we safe to assume that all instances of FileProvider will use the forward slash? Should there be something akin … |
brennie | |
Format it using parenthesis so you don't need the backslash, e.g. if get_meta and search_file or not file_name and (search_file … |
brennie | |
Like I mentioned elsewhere, KeyError probably isn't specific enough (and might accidentally bubble up from somewhere unintentically. |
brennie | |
You usually don't want to use just except because this can catch things you probably don't want to catch, e.g. … |
brennie | |
Blank line between these. |
brennie | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
All test methods should have a docstring describing what they are testing. Here and elsewhere. |
brennie | |
file_path should fit on the previous line. |
brennie | |
Have you found a case where this is needed? Typically, removing authentication for an account just means throwing away the … |
chipx86 | |
This text ends up getting processed as ReST (ReStructured Text), and in it, single backticks will be interpreted as a … |
chipx86 | |
Probably just filename for consistency with the rest of the codebase. |
chipx86 | |
This should probably reference path now, right? |
chipx86 | |
Let's do path instead of file_path, for consistency. Same elsewhere. |
chipx86 | |
Must be one line. |
chipx86 | |
Must be reworded to be one line. |
chipx86 | |
Blank line between these. |
chipx86 | |
I have a number of comments about this function. Given those comments, I think this can really just be: return … |
chipx86 | |
Why not just take *paths, rather than a leading argument? |
chipx86 | |
Blank line between these. This looks like it's protecting the caller from itself. It should be considered invalid to pass … |
chipx86 | |
What does this do? |
chipx86 | |
Global variables should be defined before all functions. |
chipx86 | |
Must be a single line. Same elsewhere. I'll let you look at the rest :) |
chipx86 | |
These should be able to start on the logging.error() line. You can also pass in entry and e as parameters … |
chipx86 | |
These must all be in alphabetical order. |
chipx86 | |
This information is obvious from looking at the class. Can you instead alter the documentation to describe the point of … |
chipx86 | |
related_name= should probably go on the next line. |
chipx86 | |
This is only in Django 1.7, which we are not using. |
chipx86 | |
Both need to have null=True. |
chipx86 | |
We don't use the if ... else ... form in the codebase (outside of lambdas), as it's less explicit and … |
chipx86 | |
Missing a trailing period. |
chipx86 | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
For sys modules, it's best to just import the top-level sys and access functions like sys.getsizeof. |
chipx86 | |
Isn't this the reason join_paths exists? |
chipx86 | |
The """ must be on the same line as the summary, in this case. No blank line after. |
chipx86 | |
This should be a single return FileProviderAccount.objects.create(...) statement. Also, when listing multiple lines of parameters in keyword form, you should … |
chipx86 | |
Maybe start this off at 250, to give more room for repository-related errors. |
chipx86 | |
Missing a trailing period. |
chipx86 | |
This says Client Error, but it's a Server Error. |
chipx86 | |
This should just import json and use json.loads, which will be easier to grep and read. |
chipx86 | |
Must be in alphabetical order. |
chipx86 | |
Many of these have trailing commas that shouldn't be added. |
chipx86 | |
I don't see anything adding these errors? |
chipx86 | |
"require" |
chipx86 | |
Feels like "... in order to allow access ..." might be easier to read. |
chipx86 | |
We don't explicitly list paths in our documentation in this way, so we should leave this out. I don't think … |
chipx86 | |
We should have is_mutable_by functions on FileProviderAccount for use by this. Even though the implementation is the same, we want … |
chipx86 | |
The space should go at the end of the line in the string, rather than the beginning. |
chipx86 | |
JSON" |
chipx86 | |
Should use isinstance(data, dict). |
chipx86 | |
I think this should just be an INVALID_FORM_DATA as well. We don't want a unique error code for everything right … |
chipx86 | |
This needs to list the field. See how it's done elsewhere. |
chipx86 | |
Same as above. |
chipx86 | |
What's this? |
chipx86 | |
ame as above. |
chipx86 | |
This loses out on things like count queries and pagination. Instead, get_queryset() should be returning request.user.file_provider_accounts.all(), and this function should … |
chipx86 | |
Same comment regarding where the spaces should go. |
chipx86 | |
Col: 80 E501 line too long (80 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (80 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (82 > 79 characters) |
reviewbot | |
Needs to be file_provider_content_... |
chipx86 | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 14 W291 trailing whitespace |
reviewbot | |
Col: 21 E126 continuation line over-indented for hanging indent |
reviewbot | |
Col: 17 E126 continuation line over-indented for hanging indent |
reviewbot | |
Should use six.iterkeys(...) |
chipx86 | |
I'd like this to be like the hosting service implementation, where it raises an exception if the key isn't previously … |
chipx86 | |
The file this is in should probably be called file.py, since fileproviders/fileproviderfile.py is a bit redundant. Are we going to … |
chipx86 | |
We should use constants for this. Also, the exception needs to have some useful information about the variable and value … |
chipx86 | |
Can you add a comment about this? It's not clear to me what this is trying to solve. I worry … |
chipx86 | |
Test docstrings must start with "Testing" instead of "Test". All these test-related comments apply throughout the file. |
chipx86 | |
Blank line between these. |
chipx86 | |
You can use assertIn`. We don't provide error messages in the assertions. They make the code a bit too verbose … |
chipx86 | |
You want self.assertRaises |
chipx86 | |
Blank line between these. |
chipx86 | |
True doesn't tell me anything. In cases like this, it's best to use keyword arguments. Same below. |
chipx86 | |
local variable 'length' is assigned to but never used |
reviewbot | |
These belong in the same import grouping. |
chipx86 | |
Blank line between these. |
chipx86 | |
Can you add doc comments for each of these? They're in the form of: #: Single-line summary. varname = ... … |
chipx86 | |
I think it's reasonable to standardize on '/' as a path separator everywhere, and to just assume that '/' is … |
chipx86 | |
Let's not default a path. The caller should always be explicit in what path they want to list. |
chipx86 | |
"Return" |
chipx86 | |
Instead of the modules listed as these, do: :py:class:`reviewboard.fileprovider.tree.File` etc. Same below. |
chipx86 | |
"specified path is not found" |
chipx86 | |
use :py:class: around ObjectDoesNotExist. |
chipx86 | |
"Return" Same below. |
chipx86 | |
The "If this feature ..." sentence should probably be its own paragraph, since it's an important thing that should stand … |
chipx86 | |
The "Each file ..." should be its own paragraph. |
chipx86 | |
I don't know that we need to bother with the whole part about the input stream. It's already clear that … |
chipx86 | |
The "If no file ..." should be a new paragraph. |
chipx86 | |
With path_sep going away, you can simplify this to: """Return a path composed from the given directory and file names.""" |
chipx86 | |
This can be one statement: return '/%s' % '/'.join([ ... ]) |
chipx86 | |
"Register" |
chipx86 | |
You can use logging.exception, and you won't have to pass exc_info=1. |
chipx86 | |
This reads strangely. How about: "If a file provider by that name is not found, None will be returned." |
chipx86 | |
This says it's returning the classes, but the function name says it's the names. |
chipx86 | |
viewkeys is only in Python 2.7. This should use six.iterkeys instead. |
chipx86 | |
"Register" This isn't necessarily a third party's class. Just say "Register a file provider class." |
chipx86 | |
"Unregister" You can remove "from the list of known providers." |
chipx86 | |
This model is meant to be consumed, and shouldn't know how it'll be consumed. Today, it's the API. Tomorrow, other … |
chipx86 | |
Blank line betwen these. |
chipx86 | |
For various reasons, having a JSONField with null=True will cause problems. Instead, use default={}. |
chipx86 | |
This must go last in the class. |
chipx86 | |
I'd maybe swap these. |
chipx86 | |
Needs a docstring. |
chipx86 | |
These should say "Return ..." and be fleshed out to describe the conditions upon which they're accessible/mutable. See the other … |
chipx86 | |
No parens. |
chipx86 | |
This should probably have a tearDown that resets the registered file providers. Also, how about FileProviderRegistrationTests? |
chipx86 | |
Maybe just have one of these outside of the TestCase, since all the tests are repeating the same pattern. |
chipx86 | |
That's kinda weird to assign object to this. How about just None? |
chipx86 | |
Instead of names_get, I'd just call this result. |
chipx86 | |
These two things don't match. This testcase can easily be used for more than the join_path function. The docstring should … |
chipx86 | |
Blank line between these. |
chipx86 | |
This should be done in setUp. |
chipx86 | |
"with a" Same below. |
chipx86 | |
I'd argue that a blank string shouldn't be treated as a valid component of a path. os.path.join will skip any … |
chipx86 | |
This should be more than just initialization. Just keep it as "Unit tests for FileProviderFile." Also, missing period. |
chipx86 | |
Blank line between these. |
chipx86 | |
This should be done in setUp. |
chipx86 | |
Blank line between these. |
chipx86 | |
This is about FileProviderDir, but is in the FileProviderFile tests. |
chipx86 | |
Should have a trailing comma. Same below. |
chipx86 | |
Blank line between these. Same below. |
chipx86 | |
"a Node." This shouldn't have any idea of how it's going to be subclassed and used. |
chipx86 | |
This is pretty thick and verbose. I'd have a paragraph per parameter. Also, some other comments: file_provider should be the … |
chipx86 | |
We do the strip a lot. How about instead, you add a normalize_path function to FileProvider. |
chipx86 | |
All paths should be required to be absolute (start with '/'). Once that condition can be guaranteed, you don't need … |
chipx86 | |
Use single quotes when possible. |
chipx86 | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 36 E201 whitespace after '(' |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 80 E501 line too long (80 > 79 characters) |
reviewbot | |
"with the file provider." |
chipx86 | |
I still think we should be removing this. |
chipx86 | |
This all feels like it's getting complicated again, trying to adjust for bad programming. We don't need to handle users … |
chipx86 | |
I think this is all just too complicated as well. I know this came up in Slack at one point, … |
chipx86 | |
Same. This really should just strip. It's not about protecting the caller here either, but rather about having a normalized … |
chipx86 | |
These calls will always perform a database query, even if we don't need it. It's best to avoid this. We … |
chipx86 | |
"Unit tests" |
chipx86 | |
This needs to call the parent tearDown(). |
chipx86 | |
"Unit tests" |
chipx86 | |
This needs to call the parent setUp(). |
chipx86 | |
Also needs to call the parent. |
chipx86 | |
This should probably be written to be more obvious, and to not set up a generator. I think that'll actually … |
chipx86 | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
pass isn't required on empty classes if there's a docstring. |
david | |
Should be in the imperative mood ("Normalize") |
david | |
I don't think we want to have defaults like this, because every instance of the model will have the same … |
david | |
Should be in the imperative mood ("Return") |
david | |
Should be in the imperative mood ("Return") |
david | |
Should be in the imperative mood ("Return") |
david |
- Description:
-
+ Orig: January 18, 2015
+ Started working on the File-Provider webapi, model and objects.
Added the file-provider api to the routes, and started working on pseudo-code on how the calls should work out. Started working on the model and objects for the fileprovider. Basic overview with how the object should work (with NotImplementedError for each function) as well as database schema for the model.
+ + UPDATE: January 23, 2015
+ + Updated the model and fileprovider.py to accomodate for third-party derived classes. Updated the webapi for GET (lists) and POST.
- Commit:
-
11efe84b175ba3e9fb5d7893466a6cabfaf006246f24a5400c0f5fab53851405c8a43537e631420f
- Diff:
-
Revision 2 (+310)
-
Tool: Pyflakes Processed Files: reviewboard/webapi/resources/root.py reviewboard/fileprovidersvcs/fileprovider.py reviewboard/webapi/resources/__init__.py reviewboard/fileprovidersvcs/models.py reviewboard/webapi/resources/file_provider.py Ignored Files: reviewboard/fileprovidersvcs/tests.py reviewboard/fileprovidersvcs/__init__.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/resources/root.py reviewboard/fileprovidersvcs/fileprovider.py reviewboard/webapi/resources/__init__.py reviewboard/fileprovidersvcs/models.py reviewboard/webapi/resources/file_provider.py Ignored Files: reviewboard/fileprovidersvcs/tests.py reviewboard/fileprovidersvcs/__init__.py
-
-
-
-
-
-
-
-
-
- Commit:
-
6f24a5400c0f5fab53851405c8a43537e631420f911ca9761925ae5598fc7aa6c6866a6de5ad2aaa
- Diff:
-
Revision 3 (+310)
-
Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/resources/root.py reviewboard/fileprovidersvcs/fileprovider.py reviewboard/webapi/resources/__init__.py reviewboard/fileprovidersvcs/models.py reviewboard/webapi/resources/file_provider.py Ignored Files: reviewboard/fileprovidersvcs/tests.py reviewboard/fileprovidersvcs/__init__.py Tool: Pyflakes Processed Files: reviewboard/webapi/resources/root.py reviewboard/fileprovidersvcs/fileprovider.py reviewboard/webapi/resources/__init__.py reviewboard/fileprovidersvcs/models.py reviewboard/webapi/resources/file_provider.py Ignored Files: reviewboard/fileprovidersvcs/tests.py reviewboard/fileprovidersvcs/__init__.py
-
-
- Commit:
-
911ca9761925ae5598fc7aa6c6866a6de5ad2aaa67b37678dead45247441c96e4eb01b179f7d7b90
- Diff:
-
Revision 4 (+312)
-
Tool: Pyflakes Processed Files: reviewboard/webapi/resources/root.py reviewboard/fileprovidersvcs/fileprovider.py reviewboard/webapi/resources/__init__.py reviewboard/fileprovidersvcs/models.py reviewboard/webapi/resources/file_provider.py Ignored Files: reviewboard/fileprovidersvcs/tests.py reviewboard/fileprovidersvcs/__init__.py
-
-
Are you sure you want to be setting the class variable like this? The only way to read/write it is through
FileProvider.name
, and there isn't a copy of it for each object.
I did a quick scan through your changes, and I didn't seename
being used, and you are only subclassing object, so I really don't see how this is helpful, but it's possible I'm totally wrong, but could you please explain why it's set this way? -
-
Good start. I have a few stylistic comments that are applicable throughout the change.
Along with this, I'd recommend we call the directory "fileproviders". I can see that it was based on "hostingsvcs," but that's just shorthand for "hosting services." "File provider services" are a bit long/redundant.
-
I wouldn't name names. I would just say "An interface to a service that provides online file storage."
-
-
This doesn't really say what this is about. Think of the text from an end-user's perspective. What do they want to know? Maybe something like:
"File providers allow users to easily authenticate with their online storage services and attach files to review requests."
-
-
-
Summaries can never wrap. They must be on one line, and the line length cannot exceed 79 characters.
-
When possible, use single quotes instead of double quotes.
We should also rename this function, since
list
is a reserved word. -
Blank line between these.
Imports are always in 3 sections (excluding the
__future__
imports):- Python standard library imports.
- Third-party modules (from the perspective of the module doing the import).
- In-project imports.
-
I know older code does this, but newer code can use
@cached_property
and not have to worry about thehasattr
stuff. See Django's docs on that.
- Summary:
-
[WIP] Basic layout for fileprovider with Django[WIP] FileProvider implementation with Django
- Description:
-
~ Orig: January 18, 2015
~ This FileProvider framework allows users to select files from their online file storage providers to upload directly to ReviewBoard. This includes defining the base class that can be subclassed to handle different file providers, and implementing webapi calls to allow users to interact with the back end. The webapi supports the following:
+ + - Listing files at the specified path in your file storage
+ - Searching for files in your file storage
+ - Uploading files from your file storage to ReviewBoard
+ - Fetching a file's meta-data
+ + As well as the general GET, POST, PUT and DELETE functionality.
+ + Orignal: January 18, 2015
Started working on the File-Provider webapi, model and objects.
Added the file-provider api to the routes, and started working on pseudo-code on how the calls should work out. Started working on the model and objects for the fileprovider. Basic overview with how the object should work (with NotImplementedError for each function) as well as database schema for the model.
UPDATE: January 23, 2015
Updated the model and fileprovider.py to accomodate for third-party derived classes. Updated the webapi for GET (lists) and POST.
+ + UPDATE: January 30, 2015
+ + Updated the model to have two JSONfields, and added implementation for GET, POST, DELETE, and PUT requests and their test cases.
- Commit:
-
67b37678dead45247441c96e4eb01b179f7d7b90efa4cb93102614f0d5cabeba2746edd0f2deb963
- Diff:
-
Revision 5 (+847 -1)
-
Tool: Pyflakes Processed Files: reviewboard/testing/testcase.py reviewboard/webapi/resources/__init__.py reviewboard/settings.py reviewboard/webapi/resources/file_provider.py reviewboard/fileproviders/models.py reviewboard/webapi/resources/root.py reviewboard/webapi/errors.py reviewboard/testing/fileprovider.py reviewboard/webapi/tests/urls.py reviewboard/webapi/tests/mimetypes.py reviewboard/webapi/tests/test_file_provider.py reviewboard/fileproviders/fileprovider.py Ignored Files: reviewboard/fileproviders/__init__.py reviewboard/fileproviders/tests.py Tool: PEP8 Style Checker Processed Files: reviewboard/testing/testcase.py reviewboard/webapi/resources/__init__.py reviewboard/settings.py reviewboard/webapi/resources/file_provider.py reviewboard/fileproviders/models.py reviewboard/webapi/resources/root.py reviewboard/webapi/errors.py reviewboard/testing/fileprovider.py reviewboard/webapi/tests/urls.py reviewboard/webapi/tests/mimetypes.py reviewboard/webapi/tests/test_file_provider.py reviewboard/fileproviders/fileprovider.py Ignored Files: reviewboard/fileproviders/__init__.py reviewboard/fileproviders/tests.py
-
-
-
-
-
-
-
-
-
-
-
-
-
- Description:
-
This FileProvider framework allows users to select files from their online file storage providers to upload directly to ReviewBoard. This includes defining the base class that can be subclassed to handle different file providers, and implementing webapi calls to allow users to interact with the back end. The webapi supports the following:
- Listing files at the specified path in your file storage
- Searching for files in your file storage
- Uploading files from your file storage to ReviewBoard
- Fetching a file's meta-data
As well as the general GET, POST, PUT and DELETE functionality.
Orignal: January 18, 2015
Started working on the File-Provider webapi, model and objects.
Added the file-provider api to the routes, and started working on pseudo-code on how the calls should work out. Started working on the model and objects for the fileprovider. Basic overview with how the object should work (with NotImplementedError for each function) as well as database schema for the model.
UPDATE: January 23, 2015
Updated the model and fileprovider.py to accomodate for third-party derived classes. Updated the webapi for GET (lists) and POST.
UPDATE: January 30, 2015
Updated the model to have two JSONfields, and added implementation for GET, POST, DELETE, and PUT requests and their test cases.
+ + UPDATE: February 7, 2015
+ + Made changes to the docstring for
FileProvider
objects and started working on them forfile_provider
webapi. Also, worked started on the child resource for FileProvider,file_provider_content.py
which allows search, listing of contents and obtaining meta-information. Test cases were made for those as well. Added a few new errors for file providers, and worked on test objectsFileProvider
. - Testing Done:
-
~ Test cases made for list (GET, POST) and items (GET, PUT, DELETE)
~ Test cases made for list (GET, POST) and items (GET, PUT, DELETE) for
file_provider
webapi+ Test cases made for list GET for file_provider_content
webapi - Commit:
-
efa4cb93102614f0d5cabeba2746edd0f2deb9638393330bec98f82b62846e869906bb74a62709e3
- Diff:
-
Revision 6 (+1442 -1)
-
Tool: Pyflakes Processed Files: reviewboard/testing/testcase.py reviewboard/webapi/resources/__init__.py reviewboard/settings.py reviewboard/webapi/resources/file_provider.py reviewboard/fileproviders/models.py reviewboard/webapi/resources/file_provider_content.py reviewboard/webapi/errors.py reviewboard/testing/fileprovider.py reviewboard/webapi/tests/test_file_provider_content.py reviewboard/webapi/tests/urls.py reviewboard/webapi/tests/mimetypes.py reviewboard/webapi/resources/root.py reviewboard/webapi/tests/test_file_provider.py reviewboard/fileproviders/fileprovider.py Ignored Files: reviewboard/fileproviders/__init__.py reviewboard/fileproviders/tests.py Tool: PEP8 Style Checker Processed Files: reviewboard/testing/testcase.py reviewboard/webapi/resources/__init__.py reviewboard/settings.py reviewboard/webapi/resources/file_provider.py reviewboard/fileproviders/models.py reviewboard/webapi/resources/file_provider_content.py reviewboard/webapi/errors.py reviewboard/testing/fileprovider.py reviewboard/webapi/tests/test_file_provider_content.py reviewboard/webapi/tests/urls.py reviewboard/webapi/tests/mimetypes.py reviewboard/webapi/resources/root.py reviewboard/webapi/tests/test_file_provider.py reviewboard/fileproviders/fileprovider.py Ignored Files: reviewboard/fileproviders/__init__.py reviewboard/fileproviders/tests.py
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Change Summary:
-
New commit for styling and PEP8/pyflakes
- Commit:
-
8393330bec98f82b62846e869906bb74a62709e3cb9218b72664ed6174192d6c2c40cfb8e4dbeec0
- Diff:
-
Revision 7 (+1437 -1)
-
Tool: Pyflakes Processed Files: reviewboard/testing/testcase.py reviewboard/webapi/resources/__init__.py reviewboard/settings.py reviewboard/webapi/resources/file_provider.py reviewboard/fileproviders/models.py reviewboard/webapi/resources/file_provider_content.py reviewboard/webapi/errors.py reviewboard/testing/fileprovider.py reviewboard/webapi/tests/test_file_provider_content.py reviewboard/webapi/tests/urls.py reviewboard/webapi/tests/mimetypes.py reviewboard/webapi/resources/root.py reviewboard/webapi/tests/test_file_provider.py reviewboard/fileproviders/fileprovider.py Ignored Files: reviewboard/fileproviders/__init__.py reviewboard/fileproviders/tests.py Tool: PEP8 Style Checker Processed Files: reviewboard/testing/testcase.py reviewboard/webapi/resources/__init__.py reviewboard/settings.py reviewboard/webapi/resources/file_provider.py reviewboard/fileproviders/models.py reviewboard/webapi/resources/file_provider_content.py reviewboard/webapi/errors.py reviewboard/testing/fileprovider.py reviewboard/webapi/tests/test_file_provider_content.py reviewboard/webapi/tests/urls.py reviewboard/webapi/tests/mimetypes.py reviewboard/webapi/resources/root.py reviewboard/webapi/tests/test_file_provider.py reviewboard/fileproviders/fileprovider.py Ignored Files: reviewboard/fileproviders/__init__.py reviewboard/fileproviders/tests.py
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
There should probably be a more specific exception for this (and elsewhere you're raising
KeyError
). Perhaps something along the lines of a file not found error.Also, if the file doesn't have metadata, shouldn't it return
None
or an empty dictionary instead? -
-
-
-
-
-
-
-
-
We don't use the Python ternary. Instead use a regular
if-else
ordata = {} if credentials: data = json_load(credentials)
-
We should return what the invalid form data is (e.g.,
{ 'reason': 'The credentials supplied were not parsable.' }
). -
Add some documentation that describes what the resource does in broad terms. Documentation that is added to API resources will be placed in the generated API documentation.
-
There should be an
added_in
field that describes the Review Board version the API resource was added in. This should probably be'3.0'
. -
-
-
-
-
Are we safe to assume that all instances of
FileProvider
will use the forward slash? Should there be something akin toos.path.join
andos.path.sep
on eachFileProvider
instance? -
Format it using parenthesis so you don't need the backslash, e.g.
if get_meta and search_file or not file_name and (search_file or get_meta): return INVALID_FORM_DATA
This is also probably a complex enough if statement to warrant some comments and probably should return a
'reason'
field in the error notification. -
Like I mentioned elsewhere,
KeyError
probably isn't specific enough (and might accidentally bubble up from somewhere unintentically. -
You usually don't want to use just
except
because this can catch things you probably don't want to catch, e.g.KeyboardInterrupt
.You should probably use
except Exception
.This is also something that should be logged with
logging.error
. Pass theexc_info=1
parameter and it will automatically log the exception information. -
-
-
- Description:
-
This FileProvider framework allows users to select files from their online file storage providers to upload directly to ReviewBoard. This includes defining the base class that can be subclassed to handle different file providers, and implementing webapi calls to allow users to interact with the back end. The webapi supports the following:
- Listing files at the specified path in your file storage
- Searching for files in your file storage
- Uploading files from your file storage to ReviewBoard
- Fetching a file's meta-data
As well as the general GET, POST, PUT and DELETE functionality.
Orignal: January 18, 2015
Started working on the File-Provider webapi, model and objects.
Added the file-provider api to the routes, and started working on pseudo-code on how the calls should work out. Started working on the model and objects for the fileprovider. Basic overview with how the object should work (with NotImplementedError for each function) as well as database schema for the model.
UPDATE: January 23, 2015
Updated the model and fileprovider.py to accomodate for third-party derived classes. Updated the webapi for GET (lists) and POST.
UPDATE: January 30, 2015
Updated the model to have two JSONfields, and added implementation for GET, POST, DELETE, and PUT requests and their test cases.
UPDATE: February 7, 2015
Made changes to the docstring for
FileProvider
objects and started working on them forfile_provider
webapi. Also, worked started on the child resource for FileProvider,file_provider_content.py
which allows search, listing of contents and obtaining meta-information. Test cases were made for those as well. Added a few new errors for file providers, and worked on test objectsFileProvider
.+ + Update: February 11, 2015
+ + Made changes that were suggested. Added documentation for the web api for both resources, and renamed the files.
- Commit:
-
cb9218b72664ed6174192d6c2c40cfb8e4dbeec0699beac810fa34019a658f6d7bc43807da344e22
- Diff:
-
Revision 8 (+1456 -1)
-
Tool: PEP8 Style Checker Processed Files: reviewboard/testing/testcase.py reviewboard/webapi/resources/__init__.py reviewboard/settings.py reviewboard/webapi/resources/file_provider.py reviewboard/fileproviders/models.py reviewboard/webapi/resources/root.py reviewboard/webapi/errors.py reviewboard/webapi/tests/test_file_provider_file.py reviewboard/testing/fileprovider.py reviewboard/webapi/resources/file_provider_file.py reviewboard/webapi/tests/urls.py reviewboard/webapi/tests/mimetypes.py reviewboard/webapi/tests/test_file_provider.py reviewboard/fileproviders/fileprovider.py Ignored Files: reviewboard/fileproviders/__init__.py reviewboard/fileproviders/tests.py Tool: Pyflakes Processed Files: reviewboard/testing/testcase.py reviewboard/webapi/resources/__init__.py reviewboard/settings.py reviewboard/webapi/resources/file_provider.py reviewboard/fileproviders/models.py reviewboard/webapi/resources/root.py reviewboard/webapi/errors.py reviewboard/webapi/tests/test_file_provider_file.py reviewboard/testing/fileprovider.py reviewboard/webapi/resources/file_provider_file.py reviewboard/webapi/tests/urls.py reviewboard/webapi/tests/mimetypes.py reviewboard/webapi/tests/test_file_provider.py reviewboard/fileproviders/fileprovider.py Ignored Files: reviewboard/fileproviders/__init__.py reviewboard/fileproviders/tests.py
-
-
-
-
-
-
-
-
-
-
General note on the description. Instead of putting updates there, you should leave the description as a comprehensive description of the change, and put all updates in the green banner for the draft .when you update the diff.
-
Have you found a case where this is needed? Typically, removing authentication for an account just means throwing away the credentials, which in our case would involve deleting the model instance.
-
This text ends up getting processed as ReST (ReStructured Text), and in it, single backticks will be interpreted as a sort of in-document reference. I'm not sure we need backticks here.
Same notes apply elsewhere.
-
-
-
-
-
-
-
I have a number of comments about this function. Given those comments, I think this can really just be:
return self.path_sep.join([ path.strip(self.path_sep) for path in paths ]) or self.path_sep
-
-
Blank line between these.
This looks like it's protecting the caller from itself. It should be considered invalid to pass non-strings or strings with invalid characters (like whitespace), rather than working around it. We could be hiding potential problems from the caller until later this way.
-
-
-
-
These should be able to start on the
logging.error()
line.You can also pass in
entry
ande
as parameters tologging.error()
.Can you also pass
exc_info=1
tologging.error()
, so that we can get detailed information when something goes wrong? -
-
This information is obvious from looking at the class. Can you instead alter the documentation to describe the point of the class's existence?
-
-
-
-
We don't use the
if ... else ...
form in the codebase (outside of lambdas), as it's less explicit and easier to misread. Can you change this to an explicit set of if/else blocks? -
-
For
sys
modules, it's best to just import the top-levelsys
and access functions likesys.getsizeof
. -
-
-
This should be a single
return FileProviderAccount.objects.create(...)
statement.Also, when listing multiple lines of parameters in keyword form, you should have only one parameter per line.
-
-
-
-
-
-
-
-
-
-
We don't explicitly list paths in our documentation in this way, so we should leave this out. I don't think this paragraph really helps in this situation.
-
We should have
is_mutable_by
functions onFileProviderAccount
for use by this. Even though the implementation is the same, we want a concept of "can this FileProviderAccount by changed by this user." -
-
-
-
I think this should just be an
INVALID_FORM_DATA
as well. We don't want a unique error code for everything right now. -
-
-
-
-
This loses out on things like count queries and pagination. Instead,
get_queryset()
should be returningrequest.user.file_provider_accounts.all()
, and this function should be removed to allow the parent to be used. -
-
- Change Summary:
-
Split the fileprovider webapi and related files into a new review request, also made changes to reflect suggestions.
- Commit:
-
699beac810fa34019a658f6d7bc43807da344e22529dd911a3525cd8d73f1a265cfa0d3d79fbb8d4
-
Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
-
- Change Summary:
-
Updated the description, summary and testing done.
- Summary:
-
[WIP] FileProvider implementation with Django[WIP] FileProvider module implementation with Django
- Description:
-
~ This FileProvider framework allows users to select files from their online file storage providers to upload directly to ReviewBoard. This includes defining the base class that can be subclassed to handle different file providers, and implementing webapi calls to allow users to interact with the back end. The webapi supports the following:
~ The FileProvider module allows users to select files from their online file storage providers and choose which files to upload to ReviewBoard for file attachments. This module consists of the following files
~ - Listing files at the specified path in your file storage
~ - Searching for files in your file storage
~ reviewboard/fileproviders/model.py
: the Django model for representing file provider accounts for different users and file providers
~ reviewboard/fileproviders/fileprovider.py
: the abstract FileProvider object to interact with the file providers.
- - Uploading files from your file storage to ReviewBoard
- - Fetching a file's meta-data
~ As well as the general GET, POST, PUT and DELETE functionality.
~ Anyone who wishes to support a particular file provider can do so by taking creating a derived class from
FileProvider
and implement the object's methods as neccessary, as well as creating an entry point for the object under reviewboard.file_providers- - Orignal: January 18, 2015
- - Started working on the File-Provider webapi, model and objects.
- - Added the file-provider api to the routes, and started working on pseudo-code on how the calls should work out. Started working on the model and objects for the fileprovider. Basic overview with how the object should work (with NotImplementedError for each function) as well as database schema for the model.
- - UPDATE: January 23, 2015
- - Updated the model and fileprovider.py to accomodate for third-party derived classes. Updated the webapi for GET (lists) and POST.
- - UPDATE: January 30, 2015
- - Updated the model to have two JSONfields, and added implementation for GET, POST, DELETE, and PUT requests and their test cases.
- - UPDATE: February 7, 2015
- - Made changes to the docstring for
FileProvider
objects and started working on them forfile_provider
webapi. Also, worked started on the child resource for FileProvider,file_provider_content.py
which allows search, listing of contents and obtaining meta-information. Test cases were made for those as well. Added a few new errors for file providers, and worked on test objectsFileProvider
.- - Update: February 11, 2015
- - Made changes that were suggested. Added documentation for the web api for both resources, and renamed the files.
- Testing Done:
-
~ Test cases made for list (GET, POST) and items (GET, PUT, DELETE) for
file_provider
webapi~ Test cases for functions and some object method in
reviewboard/fileproviders/tests.py
- Test cases made for list GET for file_provider_content
webapi
- Change Summary:
-
Added FileProviderFile.py, a model to represent the files found by FileProvider
Updated the documentation, and pep8 styling.
Added test cases for FileProviderFile.py
- Commit:
-
529dd911a3525cd8d73f1a265cfa0d3d79fbb8d4e2bc245565738d5c5cf41b672fa109355b22824d
-
Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py reviewboard/fileproviders/fileproviderfile.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py reviewboard/fileproviders/fileproviderfile.py Ignored Files: reviewboard/fileproviders/__init__.py
-
-
- Change Summary:
-
Removed deauthenticate from the base
FileProvider
object. Updated the model to support unique constraints. Also, fixed the initialization ofFileProviderFile
to pass test cases. - Summary:
-
[WIP] FileProvider module implementation with DjangoFileProvider module implementation with Django
- Commit:
-
e2bc245565738d5c5cf41b672fa109355b22824d90c11773cd81cedf318bb8f5a64588dd3fe77865
-
Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py reviewboard/fileproviders/fileproviderfile.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py reviewboard/fileproviders/fileproviderfile.py Ignored Files: reviewboard/fileproviders/__init__.py
-
Many of my comments (particularly for the unit tests) apply in several places.
-
-
I'd like this to be like the hosting service implementation, where it raises an exception if the key isn't previously registered.
-
The file this is in should probably be called
file.py
, sincefileproviders/fileproviderfile.py
is a bit redundant.Are we going to have something similar for directotries, or other types of information? Perhaps
tree.py
would be more appropriate. -
We should use constants for this.
Also, the exception needs to have some useful information about the variable and value not being correct.
-
Can you add a comment about this? It's not clear to me what this is trying to solve.
I worry about over-compensating for badly-designed data returned by file providers.
-
Test docstrings must start with "Testing" instead of "Test".
All these test-related comments apply throughout the file.
-
-
You can use assertIn`.
We don't provide error messages in the assertions. They make the code a bit too verbose and aren't really that useful in practice. I'd remove them from all tests.
-
-
-
- Change Summary:
-
Changed assertion as appropriate for the test cases. Removed error messages from assertions. Changed fileproviderfile.py to tree.py and separated the objects as necessary, and refactored any reference to the old FileProviderFile. Any pep8, other style changes and suggestions from reviews were also added.
- Commit:
-
90c11773cd81cedf318bb8f5a64588dd3fe778658f023e1b4d81c91f15ed773f0e2ed013ff4e0fd4
-
Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
-
- Change Summary:
-
Removed unused variable
- Commit:
-
8f023e1b4d81c91f15ed773f0e2ed013ff4e0fd4d6ae24d2fdfdfb719a7b0cfdce7dd0be7b7bfae9
-
Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
- Change Summary:
-
Refactored naming of variables:
path --> dir file_path --> node_path
Updated the documentation and naming to reflect new refactored names
- Commit:
-
d6ae24d2fdfdfb719a7b0cfdce7dd0be7b7bfae94423faf1b6ac4fe96115b111508460ed4439ae4e
-
Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
- Change Summary:
-
Changed the initializer for Node to take in a full path, and split it accord
Changes to the test case to reflect these changes.
- Commit:
-
4423faf1b6ac4fe96115b111508460ed4439ae4e615484e058bc358f13950f80168729d2fd712651
-
Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
-
There's a lot of comments here, but most are just documentation-related. That's a good thing! Getting into the low-hanging fruit and out of the big design stuff. You should be able to get through most of these pretty quickly.
-
-
-
Can you add doc comments for each of these? They're in the form of:
#: Single-line summary. varname = ... #: Single-line summary. #: #: Multi-line #: description. varname = ...
-
I think it's reasonable to standardize on '/' as a path separator everywhere, and to just assume that '/' is the root. No need to define variables. It'll just make things more complicated later.
-
-
-
Instead of the modules listed as these, do:
:py:class:`reviewboard.fileprovider.tree.File`
etc.
Same below.
-
-
-
-
The "If this feature ..." sentence should probably be its own paragraph, since it's an important thing that should stand out.
-
-
I don't know that we need to bother with the whole part about the input stream. It's already clear that a Django File instance must be returned, with all the requirements that come with that.
-
-
With
path_sep
going away, you can simplify this to:"""Return a path composed from the given directory and file names."""
-
-
-
-
This reads strangely. How about: "If a file provider by that name is not found, None will be returned."
-
-
-
-
-
This model is meant to be consumed, and shouldn't know how it'll be consumed. Today, it's the API. Tomorrow, other things might use this. We should avoid saying how a model will be used, but rather what it's there for (storing information needed to authenticate and communicate with an online file provider).
-
-
For various reasons, having a
JSONField
withnull=True
will cause problems. Instead, usedefault={}
. -
-
-
-
These should say "Return ..." and be fleshed out to describe the conditions upon which they're accessible/mutable. See the other equivalent functions in other classs for examples.
-
-
This should probably have a
tearDown
that resets the registered file providers.Also, how about
FileProviderRegistrationTests
? -
Maybe just have one of these outside of the TestCase, since all the tests are repeating the same pattern.
-
-
-
These two things don't match.
This testcase can easily be used for more than the join_path function. The docstring should just say it's testing FileProvider functions.
-
-
-
-
I'd argue that a blank string shouldn't be treated as a valid component of a path.
os.path.join
will skip any blank strings. -
This should be more than just initialization. Just keep it as "Unit tests for FileProviderFile."
Also, missing period.
-
-
-
-
-
-
-
-
This is pretty thick and verbose.
I'd have a paragraph per parameter.
Also, some other comments:
file_provider
should be the first parameter (pretty common to have the owner of an object be the first, in these situations).path
would be better thannode_path
.meta_information
is better asmetadata
.
-
-
All paths should be required to be absolute (start with
'/'
).Once that condition can be guaranteed, you don't need this
if
statement. You can just do thersplit
. -
- Change Summary:
-
Add changes as suggested from reviews.
- documentation clean-up - changes to reviewboard.fileproviders.tree.Node initalization and variable - added normalize_path and changed join_path for FileProvider object - add more documentation for some items - test classes for FileProviderRegistrationTests turned into one class
- Commit:
-
615484e058bc358f13950f80168729d2fd712651ac51225ff5e9166f270aeb7545caa6128d03a8d4
-
Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
-
-
-
-
-
-
- Change Summary:
-
Updated to fix for PEP-8 and Pyflakes styling.
- Commit:
-
ac51225ff5e9166f270aeb7545caa6128d03a8d49d4c7dfe8c913ca2731ef62e12f0d1b7e70a7033
-
Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
- Change Summary:
-
Updated description to include reviewboard/fileproviders/tree.py
- Description:
-
The FileProvider module allows users to select files from their online file storage providers and choose which files to upload to ReviewBoard for file attachments. This module consists of the following files
reviewboard/fileproviders/model.py
: the Django model for representing file provider accounts for different users and file providers
reviewboard/fileproviders/fileprovider.py
: the abstract FileProvider object to interact with the file providers.
+ reviewboard/fileproviders/tree.py
: contains a base Node object, which can be used to represent files and directories found in the online file providers.
Anyone who wishes to support a particular file provider can do so by taking creating a derived class from
FileProvider
and implement the object's methods as neccessary, as well as creating an entry point for the object under reviewboard.file_providers
- Change Summary:
-
Added new error NodeNotFound, to reflect changes made in /r/6948.
Fixed error in testing of FileProviderRegistrationTests, where list was used for hashing instead of name.
Updated documentation for reviewboard.fileproviders.fileprovider.FileProvider to reflect the new error and fixed mistakes.
- Commit:
-
9d4c7dfe8c913ca2731ef62e12f0d1b7e70a7033bc5a01c95cb73bbe1c6f8ff8e5c523b696963286
-
Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
- Description:
-
The FileProvider module allows users to select files from their online file storage providers and choose which files to upload to ReviewBoard for file attachments. This module consists of the following files
reviewboard/fileproviders/model.py
: the Django model for representing file provider accounts for different users and file providers
reviewboard/fileproviders/fileprovider.py
: the abstract FileProvider object to interact with the file providers.
reviewboard/fileproviders/tree.py
: contains a base Node object, which can be used to represent files and directories found in the online file providers.
+ reviewboard/fileproviders/errors.py
: contains error objects for the FileProvider framework
Anyone who wishes to support a particular file provider can do so by taking creating a derived class from
FileProvider
and implement the object's methods as neccessary, as well as creating an entry point for the object under reviewboard.file_providers
-
-
-
-
This all feels like it's getting complicated again, trying to adjust for bad programming. We don't need to handle users typing in paths. We really should just be requiring code to be forming valid paths to begin with.
-
I think this is all just too complicated as well. I know this came up in Slack at one point, but I really believe that it's the caller's fault if they're providing a path with, say, nothing between delimiters, or with
..
, or whatever. Just like a URL, the path needs to be correct to start with. That's got to be the responsibility of the caller. -
Same. This really should just strip. It's not about protecting the caller here either, but rather about having a normalized path ready to join new path items to.
-
These calls will always perform a database query, even if we don't need it. It's best to avoid this.
We can do that by checking
self.user_id
againstuser.pk
. That means checkinguser.is_authenticated()
first, though, like:return user.is_authenticated() and self.user_id == user.pk
-
-
-
-
-
-
This should probably be written to be more obvious, and to not set up a generator. I think that'll actually be more heavy than just:
path_parts = path.rsplit(..., 1) self.dir = file_provider.normalize_path(parts[0]) self.name = file_provider.normalize_path(parts[1])
It's more verbose, but we don't create a generator, and the intentions are clear.
- Change Summary:
-
Removed
path_sep
fromFileProvider
objects.Made a simple
join_path
, to not accomodate bad input. Just join the paths and assume it starts from root.normalize_path
now only strips white space and slashes.Initialization of
Node
objects now include a simpler set up fordir
andname
variables.More efficient checking of permission in models using ID instead of users.
Updated test cases to match new changes.
- Commit:
-
bc5a01c95cb73bbe1c6f8ff8e5c523b696963286fae591b52d94f2b9ce9e658cbaa02a1fad6935b2
-
Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
- Change Summary:
-
Moved
authenticated
variable from Class variable to a variable for objects in FileProvider. - Commit:
-
fae591b52d94f2b9ce9e658cbaa02a1fad6935b263ac2039e73825d9935129af6deaccd3e1036b88
-
Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
-
- Change Summary:
-
Removed white space.
- Commit:
-
63ac2039e73825d9935129af6deaccd3e1036b883c144d6344d556f7357f841a2ebf46953db335d9
-
Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py
- Change Summary:
-
Changed the
search
fuction for fileproviders to require path as input. Also updated search description to be more exact about what it does (find similar things). - Commit:
-
3c144d6344d556f7357f841a2ebf46953db335d9c9561cb8e1aac994f9b36f79e9cb3167a98dee14
-
Tool: PEP8 Style Checker Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py Tool: Pyflakes Processed Files: reviewboard/fileproviders/tests.py reviewboard/fileproviders/tree.py reviewboard/fileproviders/errors.py reviewboard/fileproviders/fileprovider.py reviewboard/fileproviders/models.py Ignored Files: reviewboard/fileproviders/__init__.py