Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 3fa6c4f

Browse files
committed
Merge branch 'saltduck-data-folder'
2 parents 92ca742 + 3ddc1ea commit 3fa6c4f

File tree

8 files changed

+114
-87
lines changed

8 files changed

+114
-87
lines changed

api/restapi.py

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _setContentDispositionAndSend(file_path, extension, content_type):
132132
if self.db.filemap.get_file(request.args["hash"][0]) is not None:
133133
image_path = self.db.filemap.get_file(request.args["hash"][0])
134134
else:
135-
image_path = DATA_FOLDER + "cache/" + request.args["hash"][0]
135+
image_path = os.path.join(DATA_FOLDER, "cache", request.args["hash"][0])
136136
if not os.path.exists(image_path) and "guid" in request.args:
137137
node = None
138138
for connection in self.protocol.values():
@@ -726,7 +726,8 @@ def respond(success):
726726
else:
727727
request.write(json.dumps({"success": False, "reason": success}))
728728
request.finish()
729-
file_path = DATA_FOLDER + "store/contracts/in progress/" + request.args["id"][0] + ".json"
729+
file_name = request.args["id"][0] + ".json"
730+
file_path = os.path.join(DATA_FOLDER, "store", "contracts", "in progress", file_name)
730731
with open(file_path, 'r') as filename:
731732
order = json.load(filename, object_pairs_hook=OrderedDict)
732733
c = Contract(self.db, contract=order, testnet=self.protocol.testnet)
@@ -762,23 +763,37 @@ def upload_image(self, request):
762763
for image in request.args["image"]:
763764
img = image.decode('base64')
764765
hash_value = digest(img).encode("hex")
766+
<<<<<<< HEAD
765767
with open(DATA_FOLDER +"store/media/" + hash_value, 'wb') as outfile:
766768
outfile.write(img)
767769
self.db.filemap.insert(hash_value, "store/media/" + hash_value)
770+
=======
771+
with open(os.path.join(DATA_FOLDER, "store", "media", hash_value), 'wb') as outfile:
772+
outfile.write(img)
773+
self.db.filemap.insert(hash_value, os.path.join(DATA_FOLDER, "store", "media", hash_value))
774+
>>>>>>> dbb6784f4627c543b4611e825e2729c60f46cb1b
768775
ret.append(hash_value)
769776
elif "avatar" in request.args:
770777
avi = request.args["avatar"][0].decode("base64")
771778
hash_value = digest(avi).encode("hex")
772-
with open(DATA_FOLDER + "store/avatar", 'wb') as outfile:
779+
with open(os.path.join(DATA_FOLDER, "store", "avatar"), 'wb') as outfile:
773780
outfile.write(avi)
781+
<<<<<<< HEAD
774782
self.db.filemap.insert(hash_value, "store/avatar")
783+
=======
784+
self.db.filemap.insert(hash_value, os.path.join(DATA_FOLDER, "store", "avatar"))
785+
>>>>>>> dbb6784f4627c543b4611e825e2729c60f46cb1b
775786
ret.append(hash_value)
776787
elif "header" in request.args:
777788
hdr = request.args["header"][0].decode("base64")
778789
hash_value = digest(hdr).encode("hex")
779-
with open(DATA_FOLDER + "store/header", 'wb') as outfile:
790+
with open(os.path.join(DATA_FOLDER, "store", "header"), 'wb') as outfile:
780791
outfile.write(hdr)
792+
<<<<<<< HEAD
781793
self.db.filemap.insert(hash_value, "store/header")
794+
=======
795+
self.db.filemap.insert(hash_value, os.path.join(DATA_FOLDER, "store", "header"))
796+
>>>>>>> dbb6784f4627c543b4611e825e2729c60f46cb1b
782797
ret.append(hash_value)
783798
request.write(json.dumps({"success": True, "image_hashes": ret}, indent=4))
784799
request.finish()
@@ -798,9 +813,13 @@ def respond(success):
798813
else:
799814
request.write(json.dumps({"success": False, "reason": success}))
800815
request.finish()
816+
<<<<<<< HEAD
801817
file_path = DATA_FOLDER + "purchases/in progress/" + request.args["id"][0] + ".json"
802818
if not os.path.exists(file_path):
803819
file_path = DATA_FOLDER + "purchases/trade receipts/" + request.args["id"][0] + ".json"
820+
=======
821+
file_path = os.path.join(DATA_FOLDER, "purchases", "in progress", request.args["id"][0] + ".json")
822+
>>>>>>> dbb6784f4627c543b4611e825e2729c60f46cb1b
804823
with open(file_path, 'r') as filename:
805824
order = json.load(filename, object_pairs_hook=OrderedDict)
806825
c = Contract(self.db, contract=order, testnet=self.protocol.testnet)
@@ -1152,27 +1171,27 @@ def get_order(self, request):
11521171
#TODO: if this is either a funded direct payment sale or complete moderated sale but
11531172
#TODO: the payout tx has not hit the blockchain, rebroadcast.
11541173

1155-
if os.path.exists(DATA_FOLDER + "purchases/unfunded/" + request.args["order_id"][0] + ".json"):
1156-
file_path = DATA_FOLDER + "purchases/unfunded/" + request.args["order_id"][0] + ".json"
1174+
filename = request.args["order_id"][0] + ".json"
1175+
if os.path.exists(os.path.join(DATA_FOLDER, "purchases", "unfunded", filename)):
1176+
file_path = os.path.join(DATA_FOLDER, "purchases", "unfunded", filename)
11571177
status = self.db.purchases.get_status(request.args["order_id"][0])
1158-
elif os.path.exists(DATA_FOLDER + "purchases/in progress/" + request.args["order_id"][0] + ".json"):
1159-
file_path = DATA_FOLDER + "purchases/in progress/" + request.args["order_id"][0] + ".json"
1178+
elif os.path.exists(os.path.join(DATA_FOLDER, "purchases", "in progress", filename)):
1179+
file_path = os.path.join(DATA_FOLDER, "purchases", "in progress", filename)
11601180
status = self.db.purchases.get_status(request.args["order_id"][0])
1161-
elif os.path.exists(DATA_FOLDER + "purchases/trade receipts/" + request.args["order_id"][0] + ".json"):
1162-
file_path = DATA_FOLDER + "purchases/trade receipts/" + request.args["order_id"][0] + ".json"
1181+
elif os.path.exists(os.path.join(DATA_FOLDER, "purchases", "trade receipts", filename)):
1182+
file_path = os.path.join(DATA_FOLDER, "purchases", "trade receipts", filename)
11631183
status = self.db.purchases.get_status(request.args["order_id"][0])
1164-
elif os.path.exists(DATA_FOLDER + "store/contracts/unfunded/" + request.args["order_id"][0] + ".json"):
1165-
file_path = DATA_FOLDER + "store/contracts/unfunded/" + request.args["order_id"][0] + ".json"
1184+
elif os.path.exists(os.path.join(DATA_FOLDER, "store", "contracts", "unfunded", filename)):
1185+
file_path = os.path.join(DATA_FOLDER, "store", "contracts", "unfunded", filename)
11661186
status = self.db.sales.get_status(request.args["order_id"][0])
1167-
elif os.path.exists(DATA_FOLDER + "store/contracts/in progress/" + request.args["order_id"][0] + ".json"):
1168-
file_path = DATA_FOLDER + "store/contracts/in progress/" + request.args["order_id"][0] + ".json"
1187+
elif os.path.exists(os.path.join(DATA_FOLDER, "store", "contracts", "in progress", filename)):
1188+
file_path = os.path.join(DATA_FOLDER, "store", "contracts", "in progress", filename)
11691189
status = self.db.sales.get_status(request.args["order_id"][0])
1170-
elif os.path.exists(DATA_FOLDER +
1171-
"store/contracts/trade receipts/" + request.args["order_id"][0] + ".json"):
1172-
file_path = DATA_FOLDER + "store/contracts/trade receipts/" + request.args["order_id"][0] + ".json"
1190+
elif os.path.exists(os.path.join(DATA_FOLDER, "store", "contracts", "trade receipts", filename)):
1191+
file_path = os.path.join(DATA_FOLDER, "store", "contracts", "trade receipts", filename)
11731192
status = self.db.sales.get_status(request.args["order_id"][0])
1174-
elif os.path.exists(DATA_FOLDER + "cases/" + request.args["order_id"][0] + ".json"):
1175-
file_path = DATA_FOLDER + "cases/" + request.args["order_id"][0] + ".json"
1193+
elif os.path.exists(os.path.join(DATA_FOLDER, "cases", filename)):
1194+
file_path = os.path.join(DATA_FOLDER, "cases", filename)
11761195
status = 4
11771196
else:
11781197
request.write(json.dumps({}, indent=4))

api/ws.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,11 @@ def handle_response(listings, node):
182182
}
183183
for country in l.ships_to:
184184
listing_json["listing"]["ships_to"].append(str(CountryCode.Name(country)))
185-
if not os.path.isfile(DATA_FOLDER + 'cache/' + l.thumbnail_hash.encode("hex")):
185+
if not os.path.isfile(os.path.join( \
186+
DATA_FOLDER, 'cache', l.thumbnail_hash.encode("hex"))):
186187
self.factory.mserver.get_image(node, l.thumbnail_hash)
187-
if not os.path.isfile(DATA_FOLDER + 'cache/' + listings.avatar_hash.encode("hex")):
188+
if not os.path.isfile(os.path.join( \
189+
DATA_FOLDER, 'cache', listings.avatar_hash.encode("hex"))):
188190
self.factory.mserver.get_image(node, listings.avatar_hash)
189191
self.transport.write(str(bleach.clean(
190192
json.dumps(listing_json, indent=4), tags=ALLOWED_TAGS)))

db/datastore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def get_conversations(self):
591591
handle = ""
592592
if val[0] is not None:
593593
try:
594-
with open(DATA_FOLDER + 'cache/' + g[0], "r") as filename:
594+
with open(join(DATA_FOLDER, 'cache', g[0]), "r") as filename:
595595
profile = filename.read()
596596
p = objects.Profile()
597597
p.ParseFromString(profile)

0 commit comments

Comments
 (0)