-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subdirectories #1567
Merged
Dunbaratu
merged 48 commits into
KSP-KOS:develop
from
tomekpiotrowski:new_subdirectories
May 28, 2016
Merged
Subdirectories #1567
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
253d087
Path handling types
tomekpiotrowski d9a2917
Add directory support for Archive and Harddisk
tomekpiotrowski fad654a
PathValue structure
tomekpiotrowski bf763e2
path() command
tomekpiotrowski 6e42e0f
scriptpath() command
tomekpiotrowski baf2311
Initialize VolumeItem suffixes
tomekpiotrowski 039c6e5
Make Volume:NAME settable
tomekpiotrowski 3b02c7b
Change how create file/directory handles conflicts
tomekpiotrowski 84c86c4
Add deprecation messages to old rename/delete/copy syntax
tomekpiotrowski 307a909
Add VolumeItem:ISFILE suffix
tomekpiotrowski 8cb2dd6
Add volume() function
tomekpiotrowski 22c454e
Copy implemented
tomekpiotrowski 3361a65
Harddisk persistence fix
tomekpiotrowski 1096094
Bugfix in VolumeManager
tomekpiotrowski 8cceb42
Added missing type names.
tomekpiotrowski 864e45c
Bug fixes
tomekpiotrowski ee8201f
Moar bugfixes.
tomekpiotrowski f777034
Fix edit()
tomekpiotrowski 39ed5f6
Copying unit tests
tomekpiotrowski d6c34fa
More copy() unit tests
tomekpiotrowski 53abaed
move() unit tests
tomekpiotrowski e88c262
Bug fixes
tomekpiotrowski dc71b4f
Path serialization fix
tomekpiotrowski a805f7d
Handle volumes without names
tomekpiotrowski 217862f
Fix handling cooked file names by delete()
tomekpiotrowski 0986d10
Look for boot files in 'boot' directory
tomekpiotrowski 4fac4fa
Revert "Add deprecation messages to old rename/delete/copy syntax"
tomekpiotrowski 1c94210
Volume:open should return false when item does not exist
tomekpiotrowski 16acf6a
Rename COPY(), MOVE() and DELETE()
tomekpiotrowski 92e1c01
Updated Volume documentation
tomekpiotrowski a3b9bb0
Few more GlobalPath tests
tomekpiotrowski 2e1c8df
Path documentation
tomekpiotrowski 9d3366e
Update VOLUME:OPEN documentation
tomekpiotrowski e97817d
Bugfixes
tomekpiotrowski 62c84a7
copypath() bugfixes
tomekpiotrowski ec7bbf5
More copy() tests and bugfixes
tomekpiotrowski c531db5
Volumes and VolumeItems can now be used as paths
tomekpiotrowski 08188bc
Commands->File I/O documentation page
tomekpiotrowski bb45190
Add PathValue:CHANGENAME
tomekpiotrowski 3ed5a0f
Make directories enumerable
tomekpiotrowski f509340
Removed VolumeManager's electric power code
tomekpiotrowski 6e46db0
Fix some errors on the Commands/FileIO page
tomekpiotrowski 1084423
Add Volume:ROOT suffix
tomekpiotrowski 2ba2514
Fix VolumeDirectory enumeration
tomekpiotrowski b05a5d6
Add VolumeDirectory and VolumeItem doc pages
tomekpiotrowski 05527a5
Update Volume documentation page
tomekpiotrowski b3fda23
Fix typos
tomekpiotrowski 7a4439e
Volume:NAME is now settable
tomekpiotrowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
.. _path: | ||
|
||
Path | ||
==== | ||
|
||
Represents a path. Contains suffixes that can be helpful when using and manipulating paths. You can use | ||
:ref:`path() <path_command>` to create new instances. | ||
|
||
Instances of this structure can be passed as arguments instead of ordinary, string paths, for example:: | ||
|
||
copypath("../file", path()). | ||
|
||
.. structure:: Path | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 2 1 4 | ||
|
||
* - Suffix | ||
- Type | ||
- Description | ||
|
||
* - :attr:`VOLUME` | ||
- :struct:`Volume` | ||
- Volume this path belongs to | ||
* - :attr:`SEGMENTS` | ||
- :struct:`List` of :struct:`String` | ||
- List of this path's segments | ||
* - :attr:`LENGTH` | ||
- :struct:`Scalar` | ||
- Number of segments in this path | ||
* - :attr:`NAME` | ||
- :struct:`String` | ||
- Name of file or directory this path points to | ||
* - :attr:`HASEXTENSION` | ||
- :struct:`Boolean` | ||
- True if path contains an extension | ||
* - :attr:`EXTENSION` | ||
- :struct:`String` | ||
- This path's extension | ||
* - :attr:`ROOT` | ||
- :struct:`Path` | ||
- Root path of this path's volume | ||
* - :attr:`PARENT` | ||
- :struct:`Path` | ||
- Parent path | ||
* - :meth:`CHANGENAME(name)` | ||
- :struct:`Path` | ||
- Returns a new path with its name (last segment) changed | ||
* - :meth:`CHANGEEXTENSION(extension)` | ||
- :struct:`Path` | ||
- Returns a new path with extension changed | ||
* - :meth:`ISPARENT(path)` | ||
- :struct:`Boolean` | ||
- True if `path` is the parent of this path | ||
* - :meth:`COMBINE(name1, [name2, ...])` | ||
- :struct:`Path` | ||
- Returns a new path created from this one | ||
|
||
.. attribute:: Path:VOLUME | ||
|
||
:type: :struct:`Volume` | ||
:access: Get only | ||
|
||
Volume this path belongs to. | ||
|
||
.. attribute:: Path:SEGMENTS | ||
|
||
:type: :struct:`List` of :struct:`String` | ||
:access: Get only | ||
|
||
List of segments this path contains. Segments are parts of the path separated by `/`. For example path `0:/directory/subdirectory/script.ks` contains the following segments: | ||
`directory`, `subdirectory` and `script.ks`. | ||
|
||
.. attribute:: Path:LENGTH | ||
|
||
:type: :struct:`Scalar` | ||
:access: Get only | ||
|
||
Number of this path's segments. | ||
|
||
.. attribute:: Path:NAME | ||
|
||
:type: :struct:`String` | ||
:access: Get only | ||
|
||
Name of file or directory this path points to (same as the last segment). | ||
|
||
|
||
.. attribute:: Path:HASEXTENSION | ||
|
||
:type: :struct:`Boolean` | ||
:access: Get only | ||
|
||
True if the last segment of this path has an extension. | ||
|
||
.. attribute:: Path:EXTENSION | ||
|
||
:type: :struct:`String` | ||
:access: Get only | ||
|
||
Extension of the last segment of this path. | ||
|
||
.. attribute:: Path:ROOT | ||
|
||
:type: :struct:`Path` | ||
:access: Get only | ||
|
||
Returns a new path that points to the root directory of this path's volume. | ||
|
||
.. attribute:: Path:PARENT | ||
|
||
:type: :struct:`Path` | ||
:access: Get only | ||
|
||
Returns a new path that points to this path's parent. This method will throw an exception if this path does not have a parent (its length is 0). | ||
|
||
.. method:: Path:CHANGENAME(name) | ||
|
||
:parameter name: :struct:`String` new path name | ||
:return: :struct:`Path` | ||
|
||
Will return a new path with the value of the last segment of this path replaced (or added if there's none). | ||
|
||
.. method:: Path:CHANGEEXTENSION(extension) | ||
|
||
:parameter extension: :struct:`String` new path extension | ||
:return: :struct:`Path` | ||
|
||
Will return a new path with the extension of the last segment of this path replaced (or added if there's none). | ||
|
||
.. method:: Path:ISPARENT(path) | ||
|
||
:parameter path: :struct:`Path` path to check | ||
:return: :struct:`Boolean` | ||
|
||
Returns true if `path` is the parent of this path. | ||
|
||
.. method:: Path:COMBINE(name1, [name2, ...]) | ||
|
||
:parameter name: :struct:`String` segments to add | ||
:return: :struct:`Path` | ||
|
||
Will return a new path created by adding segments to this path. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for making the extension different from the rest of the name, in the sense that the extension can be changed with a suffix method but the rest of the name cannot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the way to change the rest of the path name be to do a chain of
Or are you specifically looking for a way to generate a path with the same folder and extension but a different file name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Unix world (and therefore also Macs from OSX onward), the extension was never a separate special field. The filename IS just one string including the extension. (From the way the filesystem "thinks" in most UNIX systems, the humans who choose the filename strings seem to like using ones with exactly one period character in them a lot of the time for some mysterious reason the filesystem doesn't understand or care about.) The notion of an "extension" is a higher level logical abstraction consisting of that substring of the whole filename that comes after the lastmost period, if there is one. Things like GUI file managers, and system libraries, apply this abstraction on top. The filesystem itself has no such thing as "extensions".
For all I know the newer Windows filesystems may be the same way now too. The notion of a file "extension" came from DOS and FAT originally.
So this is why it looks very arbitrary and weird to me for there to be a rule that you can change the extension but not the rest of the name, via the PATH suffixes. The extension is nothing more than a subset of the filename. Either you should be able to change it via PATH, or you shouldn't be able to. Not this strange "it depends on which part of it you're trying to change".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point.
To be honest IIRC I took a couple of suffixes straight from C#'s Path class, this was one of them. I thought it could be useful to expose that functionality to the user. I see no problem with adding a similar
CHANGENAME
suffix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the description in the RST file, I didn't understand how the
combine
suffix works.If it really is just "return a new path with a new filename in the same directory as this path", then it gives me what I'm looking for. I'm not looking for a suffix that ONLY changes the base substring of the name. I see that as just as arbitrary as one that only changes the extension substring of the name. I'm looking for how to change the whole name in one go, and treat it like it really is - as a single string - ignoring the "base dot extension" abstraction layer entirely and just changing the file's actual raw name, which includes the base, the period, and the extension in one string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine with
CHANGENAME
iffpath:changename(newname)
does exactly the same thing aspath:parent:combine(newname)
currently does, but not if it only works on the base name and not the extension. (The thing @hvacengi was guessing I might have meant up above is definitely not what I wanted.) We need to be fundamentally consistent in our terminology. When we say "file name" elsewhere, we do include the extension (i.e.path:name
returns "prog.ks" rather than just "prog"):changename
should be the same and the "name" it is changing should be the same "name" that:name
is returning.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was my intention to make it behave like
path:parent:combine(newname)
.I assumed extension to be the part of the file name after last dot (if any). So file name includes extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love it if we could get to a point where we always refer to files with the extension.
run test.
should run a file named "test" not "test.ks" (or "test.ksm", that inference is part of the problem).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the behavior that was introduced by one of my previous PRs is a good compromise between what you mention and being backwards compatible.
That is when you create a file you need to specify the full name, no extensions are added by kOS. However when you access a file kOS tries to add '.ks' and '.ksm' to the file name if it doesn't find the original one. I've kept the same behavior in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added
PATH:CHANGENAME(name)