Skip to content

Commit 832a62f

Browse files
committed
Added support for the 'list' action
1 parent 182b3bd commit 832a62f

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Methods
5555
>>> ns.dir(NETSTORAGE_PATH)
5656
>>> ns.download(NETSTORAGE_SOURCE, LOCAL_DESTINATION)
5757
>>> ns.du(NETSTORAGE_PATH)
58+
>>> ns.list(NETSTORAGE_PATH)
5859
>>> ns.mkdir(NETSTORAGE_PATH + DIRECTORY_NAME)
5960
>>> ns.mtime(NETSTORAGE_PATH, TIME) # ex) TIME: int(time.time())
6061
>>> ns.quick_delete(NETSTORAGE_DIR) # needs to be enabled on the CP Code
@@ -145,4 +146,4 @@ Unless required by applicable law or agreed to in writing, software
145146
distributed under the License is distributed on an "AS IS" BASIS,
146147
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
147148
See the License for the specific language governing permissions and
148-
limitations under the License.
149+
limitations under the License.

akamai/netstorage/netstorage.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ def dir(self, ns_path):
136136
method='GET',
137137
path=ns_path)
138138

139+
def list(self, ns_path):
140+
return self._request(action='list&format=xml',
141+
method='GET',
142+
path=ns_path)
143+
139144
def download(self, ns_source, local_destination=''):
140145
if ns_source.endswith('/'):
141146
raise NetstorageError("[NetstorageError] Nestorage download path shouldn't be a directory: {0}".format(ns_source))

cms_netstorage.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def print_result(response, action):
4343
action_list = '''\
4444
dir: to list the contents of the directory /123456
4545
dir /123456
46+
list: to list the contents of the directory /123456 and all subdirectories in one call
47+
list /123456
4648
upload: to upload file.txt to /123456 directory
4749
upload file.txt /123456/ or
4850
upload file.txt /123456/file.txt
@@ -98,6 +100,8 @@ def print_result(response, action):
98100
ok, res = ns.download(args[0], args[1])
99101
elif options.action == 'du':
100102
ok, res = ns.du(args[0])
103+
elif options.action == 'list':
104+
ok, res = ns.list(args[0])
101105
elif options.action == 'mkdir':
102106
ok, res = ns.mkdir(args[0])
103107
elif options.action == 'mtime':
@@ -127,4 +131,4 @@ def print_result(response, action):
127131
parser.print_help()
128132
else:
129133
print("You should input hostname, keyname, key and action.\n")
130-
parser.print_help()
134+
parser.print_help()

test/test_netstorage.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ def test_netstorage(self):
8181
self.assertEqual(True, ok, "dir fail.")
8282
print("[TEST] dir {0} done".format("/" + self.cpcode_path))
8383

84+
# dir
85+
ok, _ = self.ns.list("/" + self.cpcode_path)
86+
self.assertEqual(True, ok, "list fail.")
87+
print("[TEST] list {0} done".format("/" + self.cpcode_path))
88+
8489
# mkdir
8590
ok, _ = self.ns.mkdir(self.temp_ns_dir)
8691
self.assertEqual(True, ok, "mkdir fail.")
@@ -173,4 +178,4 @@ def test_netstorage_exception(self):
173178

174179

175180
if __name__ == '__main__':
176-
unittest.main()
181+
unittest.main()

0 commit comments

Comments
 (0)