Skip to content

Commit

Permalink
Access: python shim:
Browse files Browse the repository at this point in the history
* Use QFS client cd / pwd
* Pass encoding and "errors" to open, create.
* Use unicode objects instead of c string as parameters instead of c strings where possible / make sense in order to minimize encoding conversion.
Examples: add more tests / examples to QFS python sample code.
  • Loading branch information
mikeov committed Nov 21, 2023
1 parent 9694f23 commit 7b1ba23
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 218 deletions.
24 changes: 23 additions & 1 deletion examples/python/qfssample.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def main():
client = None
server = ParseConfig(sys.argv[1])

# f = open("ztest", "wt", encoding="utf-8", errors="ignore")
# print("encoding: " + f.encoding)
# print("mode: " + f.mode)
# print("file: " + str(f))
# return 0
try:
client = qfs.client(server)
except:
Expand All @@ -82,6 +87,7 @@ def main():
+ "Make sure that the meta- and chunkservers are running."
)

print("qfs client: " + str(client))
testBaseDir = "qfssample_base"
testDirs = ("dir1", "dir2")
testFile1 = "dir1/file1"
Expand Down Expand Up @@ -160,6 +166,8 @@ def main():
err_exit("%s is not in expected list %r" % (node, expected))
print("Created paths are in order.")

print("readdirpus: " + str(client.readdirplus(testBaseDir + "/dir1")))

filePath1 = testBaseDir + "/" + testFile1
filePath2 = testBaseDir + "/" + testFile2

Expand Down Expand Up @@ -192,10 +200,24 @@ def main():
f2.close()
print("File2 contents are in order")

f2 = client.open(filePath2, "r")
f2 = client.open(filePath2, "r", "utf-8", "ignore")
res = f2.data_verify()
print("data verify %s: %d" % (filePath2, res))
locs = f2.chunk_locations(0)
print("chunk locations %s: %s" % (filePath2, str(locs)))
print("file: " + str(f2))
f2.close()
f2.open("wb+")
f2.truncate(0)
print("file: " + str(f2))
f2.close()
nc = client.getNumChunks(filePath1)
print("%s chunks: %s" % (filePath1, str(nc)))

stat = client.stat(filePath1)
print("full stat %s: %s" % (filePath1, str(stat)))
fstat = client.fullstat(filePath1)
print("full full stat %s: %s" % (filePath1, str(fstat)))

client.rmdirs(testBaseDir)

Expand Down
Loading

0 comments on commit 7b1ba23

Please sign in to comment.