Add to_sys_name() to replace the win32 tests

A holdover from DOS 8.3 filenames, files on Windows cannot end with a
dot.  We append a - to such names on Windows platforms in all
operations, which should solve the problem, but we'd just duplicated
that code about a dozen times.  No need, do it once and we can add
whatever filesystem rules for the host system we need to in one spot.
This commit is contained in:
T. Joseph Carter 2017-06-21 05:50:22 -07:00
parent 54c91f70da
commit 795694dbb2

37
cppo
View File

@ -746,6 +746,13 @@ def usage(exitcode=1):
print(sys.modules[__name__].__doc__)
quitNow(exitcode)
def to_sys_name(name):
if os.name == 'nt':
if name[-1] == '.':
name += '-'
name = name.replace('./', '.-/')
return name
# --- ID bashbyter functions (adapted)
def decToHex(arg1):
@ -1006,48 +1013,28 @@ def to_bytes(val):
def touch(filePath, modTime=None):
# http://stackoverflow.com/questions/1158076/implement-touch-using-python
# print(filePath)
if (os.name == "nt"):
if filePath[-1] == ".":
filePath += "-"
filePath = filePath.replace("./", ".-/")
with open(filePath, "ab"):
with open(to_sys_name(filePath), "ab"):
os.utime(filePath, (None if (modTime is None) else (modTime, modTime)))
def mkdir(dirPath):
if (os.name == "nt"):
if dirPath[-1] == ".":
dirPath += "-"
dirPath = dirPath.replace("./", ".-/")
try:
os.mkdir(dirPath)
os.mkdir(to_sys_name(dirPath))
except FileExistsError:
pass
def makedirs(dirPath):
if (os.name == "nt"):
if dirPath[-1] == ".":
dirPath += "-"
dirPath = dirPath.replace("./", ".-/")
try:
os.makedirs(dirPath)
os.makedirs(to_sys_name(dirPath))
except OSError as e:
if (e.errno != errno.EEXIST):
raise
def loadFile(filePath):
if (os.name == "nt"):
if filePath[-1] == ".":
filePath += "-"
filePath = filePath.replace("./", ".-/")
with open(filePath, "rb") as imageHandle:
with open(to_sys_name(filePath), "rb") as imageHandle:
return imageHandle.read()
def saveFile(filePath, fileData):
if (os.name == "nt"):
if filePath[-1] == ".":
filePath += "-"
filePath = filePath.replace("./", ".-/")
with open(filePath, "wb") as imageHandle:
with open(to_sys_name(filePath), "wb") as imageHandle:
imageHandle.write(fileData)
def isnumber(number):