Skip to content

Commit de530de

Browse files
committed
INDEX_ZIP
1 parent b1b198e commit de530de

File tree

7 files changed

+52
-44
lines changed

7 files changed

+52
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ target/
6464

6565
# others
6666
.DS_Store
67+
test/secret.py
6768
spike/

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ python:
99
- "pypy"
1010
- "pypy3"
1111

12-
env:
13-
global:
14-
- secure: CU6wrK3/WuTT04eulLLrYDqVYQZEMi0KpQZQ1/+4z1k7m1+LIP5TWLNg4258Vr7bxouRJxEEGWq2cobN7cSAYshIwGWCFWoVAcf6DbVEJSsit8E93hWMrthNqU45cMlSY35lXKUfCJ6MntRWi/++UeoFAFXGsAOXDJmFTCEtq8v81d2Rw09oZLavTHxas0WCnGc+5ioAx2vld+Leknh0dNIKpGo5D+OTaT7PZEx9Y8JtwNhl1rhCCznhAFAftKBIJVOh8Yeorm58FgIcW9fk/QHZMeoQ7QaCxSWwWr1cRdMNBLAd4yjDMLF9AQc0FYqsRyArpsVk7LCbUhzOdce8NNkGUcRukaRWOq3dwKI7C7oN4JPTaKZFDYekIAr5lbcmaTS3xFh/Yluf+HvWaXkUa5dLTZrORXjUExaW0IAbIocCpVZSASgxDgq8i1PCIQ/CN8TiCaYDKiwRdNb3EYaiqbSkcDiCe1Zj4mpQl7dilxGVF0VEjHsqyvtSxW1gBZEMtZoj5ofjQV49daWLGdedTN9l8MYvlkviyyzFbeERQKEKXhbheO130H3iErx21dKsXOlOaMiTaaV4ko2E7zWIMUs097oYMmmFswBpEmA5IhW6Mq/1a8mQfvIHUv9gBwG7K1rkxWT4e7qW0QrKD4eJLLLLtu7DCtpOfBI0L4wpNjk=
15-
1612
install:
1713
- pip install -r requirements.txt
1814

1915
script:
16+
- export TEST_MODE=TRAVIS
17+
- export NS_HOSTNAME=$NS_HOSTNAME
18+
- export NS_KEYNAME=$NS_KEYNAME
2019
- export NS_KEY=$NS_KEY
21-
- python test_netstorage.py
20+
- export NS_CPCODE=$NS_CPCODE
21+
- python test/test_netstorage.py

README.rst

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,21 @@ Example
3030

3131
.. code-block:: python
3232
33-
>>> from akamai.netstorage import Netstorage, NetstorageError
34-
>>>
35-
>>> NS_HOSTNAME = 'astin-nsu.akamaihd.net'
36-
>>> NS_KEYNAME = 'astinapi'
37-
>>> NS_KEY = 'xxxxxxxxxx' # Don't expose NS_KEY on public repository.
38-
>>> NS_CPCODE = '360949'
39-
>>>
40-
>>> ns = Netstorage(NS_HOSTNAME, NS_KEYNAME, NS_KEY, ssl=False) # ssl is optional (default: False)
41-
>>> local_source = 'hello.txt'
42-
>>> netstorage_destination = '/{0}/hello.txt'.format(NS_CPCODE) # or '/{0}/'.format(NS_CPCODE) is same.
43-
>>> ok, response = ns.upload(local_source, netstorage_destination)
44-
>>> ok
45-
True # means 200 OK; If False, it's not 200 OK
46-
>>> response
47-
<Response [200]> # Response object from requests.get|post|put
48-
>>> response.status_code
49-
200
50-
>>> response.text
51-
'<HTML>Request Processed</HTML>'
52-
>>>
53-
>>> response.encoding
54-
'ISO-8859-1' # requests makes educated guesses about the encoding of the response based on the HTTP headers.
55-
>>> response.encoding = 'utf-8' # You can change the response encoding.
56-
>>>
33+
from akamai.netstorage import Netstorage, NetstorageError
34+
35+
NS_HOSTNAME = 'astin-nsu.akamaihd.net'
36+
NS_KEYNAME = 'astinapi'
37+
NS_KEY = 'xxxxxxxxxx' # Don't expose NS_KEY on public repository.
38+
NS_CPCODE = '360949'
39+
40+
ns = Netstorage(NS_HOSTNAME, NS_KEYNAME, NS_KEY, ssl=False) # ssl is optional (default: False)
41+
local_source = 'hello.txt'
42+
netstorage_destination = '/{0}/hello.txt'.format(NS_CPCODE) # or '/{0}/'.format(NS_CPCODE) is same.
43+
ok, response = ns.upload(local_source, netstorage_destination)
44+
# "ok": True means 200 OK; If False, it's not 200 OK
45+
# "response": <Response [200]> # Response object from requests.get|post|put
46+
print(response.text)
47+
# '<HTML>Request Processed</HTML>'
5748
5849
Methods
5950
-------
@@ -71,25 +62,27 @@ Methods
7162
>>> ns.rmdir(NETSTORAGE_DIR)
7263
>>> ns.stat(NETSTORAGE_PATH)
7364
>>> ns.symlink(NETSTORAGE_TARGET, NETSTORAGE_DESTINATION)
74-
>>> ns.upload(LOCAL_SOURCE, NETSTORAGE_DESTINATION)
65+
>>> ns.upload(LOCAL_SOURCE, NETSTORAGE_DESTINATION, INDEX_ZIP)
7566
>>>
7667
>>>
7768
>>> # INFO: Return (True/False, Response Object from requests.get|post|put)
7869
>>> # True means 200 OK.
7970
>>> # INFO: Can "upload" Only a single file, not a directory.
71+
>>> # "upload" INDEX_ZIP value is are bool(True or False).
72+
>>> # (This supports only for FileStore)
8073
>>> # WARN: Can raise NetstorageError at all methods.
8174
>>>
8275
8376
8477
Test
8578
----
8679

87-
You can test all above methods with `unittest script <https://github.com/AstinCHOI/NetStorageKit-Python/blob/master/test_netstorage.py>`_
80+
You can test all above methods with `unittest script <https://github.com/AstinCHOI/NetStorageKit-Python/blob/master/test/test_netstorage.py>`_
8881
(NOTE: You should input NS_HOSTNAME, NS_KEYNAME, NS_KEY and NS_CPCODE in the script):
8982

9083
.. code-block:: bash
9184
92-
$ python test_netstorage.py
85+
$ python test/test_netstorage.py
9386
[TEST] dir /360949 done
9487
[TEST] mkdir /360949/048a30de-e6af-45d0-81e6-fc38bf985fb9 done
9588
[TEST] upload 6ae30c1a-289a-42a7-9d3d-f634357098b3.txt to /360949/048a30de-e6af-45d0-81e6-fc38bf985fb9/6ae30c1a-289a-42a7-9d3d-f634357098b3.txt done

akamai/netstorage/netstorage.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,19 @@ def symlink(self, ns_target, ns_destination):
178178
method='POST',
179179
path=ns_destination)
180180

181-
def upload(self, local_source, ns_destination):
181+
def upload(self, local_source, ns_destination, index_zip=False):
182182
if os.path.isfile(local_source):
183183
if ns_destination.endswith('/'):
184184
ns_destination = "{0}{1}".format(ns_destination, ntpath.basename(local_source))
185185
else:
186186
raise NetstorageError("[NetstorageError] {0} doesn't exist or is directory".format(local_source))
187-
188-
return self._request(action='upload',
187+
188+
action = 'upload'
189+
190+
if index_zip: # Support only For File Store, not Object Store.
191+
action = action + '&index-zip=1'
192+
193+
return self._request(action=action,
189194
method='PUT',
190195
source=local_source,
191196
path=ns_destination)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
setup (
1010
name = 'netstorageapi',
11-
version = '1.2.6',
11+
version = '1.2.7',
1212
description = 'Akamai Netstorage API for Python',
1313
long_description = readme,
1414
namespace_packages=['akamai'],
15-
packages=find_packages(exclude=['spike']),
15+
packages=find_packages(exclude=['spike', 'test']),
1616
install_requires = [
1717
'requests'
1818
],

test/secret_sample.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
NS_HOSTNAME = "YOUR_HOSTNAME"
2+
NS_KEYNAME = "YOUR_KEYNAME"
3+
NS_KEY = "YOUR_KEY"
4+
NS_CPCODE = "YOUR_CPCODE"

test_netstorage.py renamed to test/test_netstorage.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@
2424
import uuid
2525
import xml.etree.ElementTree as ET
2626

27+
sys.path.append("akamai/netstorage"); sys.path.append("../akamai/netstorage")
2728
from akamai.netstorage import Netstorage, NetstorageError
2829

29-
30-
NS_HOSTNAME = "astin-nsu.akamaihd.net"
31-
NS_KEYNAME = "astinapi"
32-
# from spike import secrets
33-
# NS_KEY = secrets.key # DO NOT EXPOSE IT
34-
NS_KEY = os.environ['NS_KEY']
35-
NS_CPCODE = "360949"
30+
if os.environ.get('TEST_MODE') == 'TRAVIS':
31+
NS_HOSTNAME = os.environ['NS_HOSTNAME']
32+
NS_KEYNAME = os.environ['NS_KEYNAME']
33+
NS_KEY = os.environ['NS_KEY']
34+
NS_CPCODE = os.environ['NS_CPCODE']
35+
else:
36+
import secret
37+
NS_HOSTNAME = secret.NS_HOSTNAME
38+
NS_KEYNAME = secret.NS_KEYNAME
39+
NS_KEY = secret.NS_KEY
40+
NS_CPCODE = secret.NS_CPCODE
3641

3742

3843
class TestNetstorage(unittest.TestCase):

0 commit comments

Comments
 (0)