MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / viewFile

Function viewFile

fileview.py:17–231  ·  view source on GitHub ↗
(args,scrsiz=())

Source from the content-addressed store, hash-verified

15#import uselect
16
17def viewFile(args,scrsiz=()):
18 # scrsiz can be used if running program from REPL to specify the screen dimensions
19 # first import launches with defaults but subsequent launches can use:
20 # fileview.viewFile("filename.txt",(height,width))
21
22 def chkPath(tstPath):
23 validPath = True
24 simpPath = ""
25
26 if tstPath != []:
27 savDir = os.getcwd()
28
29 for path in tstPath:
30 if path == "":
31 os.chdir("/")
32 elif os.getcwd() == "/" and path == "..":
33 validPath = False
34 break
35 elif path == ".":
36 continue
37 elif path == ".." and len(os.getcwd().split('/')) == 2:
38 os.chdir('/')
39 elif path == "..":
40 os.chdir("..")
41 elif path in os.listdir() and (os.stat(path)[0] & (2**15) == 0):
42 os.chdir(path)
43 else:
44 validPath = False
45 simpPath = ""
46 break
47
48 if validPath:
49 simpPath = os.getcwd()
50 os.chdir(savDir)
51
52 return((validPath,simpPath))
53
54 def absolutePath(argPath,currDir):
55
56 if argPath[0] == '/':
57 fullPath = argPath
58 elif currDir == '/':
59 fullPath = '/'+argPath
60 else:
61 fullPath = currDir+'/'+argPath
62
63 if len(fullPath) > 1 and fullPath[-1] == '/':
64 fullPath = fullPath[:-1]
65
66 return(fullPath)
67
68
69 if __name__ == "PyDOS":
70 global envVars
71
72 scrLines = int(envVars["_scrHeight"])
73 scrWidth = int(envVars["_scrWidth"])
74 elif scrsiz:

Callers 1

fileview.pyFile · 0.85

Calls 5

keysMethod · 0.80
absolutePathFunction · 0.70
chkPathFunction · 0.70
get_screensizeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected