t5 commited on
Commit
8cd12eb
·
1 Parent(s): 9d0a748
Files changed (2) hide show
  1. altEdit.py +16 -24
  2. wr.py +35 -14
altEdit.py CHANGED
@@ -4,7 +4,7 @@ import sys
4
  import time
5
  from ctypes import *
6
  import subprocess as p
7
- from wr import tfolder
8
 
9
  def scroll(*ww):
10
  import edit_
@@ -21,7 +21,7 @@ def ctockai( text ):
21
  text="{} 1> {} 2> {} \n".format(text,*logfile)#write
22
  ## orror(text);
23
  ip.stdin.write( text.encode("cp932"))
24
- ip.stdin.close()
25
  retcode = ip.wait()
26
  #
27
  lir=list(open(f,"rb").read() for f in logfile)
@@ -41,10 +41,10 @@ def ctod( text ,sh=True,cp="cp932",si=None):
41
  if(sh):
42
  text+="\n";
43
  ip.stdin.write( text.encode("cp932"))
44
- ip.stdin.close()
45
  elif(si):
46
  ip.stdin.write(si)
47
- ip.stdin.close()
48
 
49
  retcode=None
50
  try:
@@ -80,7 +80,7 @@ class cltof():
80
  zl.ev=th.Event()
81
  zl.lock=th.Lock()
82
  os.environ['PYTHONIOENCODING'] = 'utf-8'
83
- def ctof(zl,cb,to, text ):
84
  from wr import vcs, tp, wfd
85
  zl.ev.clear()
86
  if 0==to:to=3600*12
@@ -97,20 +97,12 @@ class cltof():
97
  ## ip = p.Popen( [("echo ff"),"1>",logfile[0],"2>",logfile[1]], shell=True )
98
  if isinstance(text,(list,tuple)): te= [*text,"1>",logfile[0],"2>",logfile[1]]
99
  elif isinstance(text,(str)):te= text+" 1> {} 2> {}".format(*logfile)
100
- ## zl.ip=ip=p.Popen(te,shell=True)
101
- zl.ip=ip=p.Popen(text,shell=True, stdout=open(logfile[0],"w"), stderr=open(logfile[1],"w"))
102
- ## zl.ip=ip = p.Popen( ['cmd /c {} 1> {} 2> {} '.format(text,*logfile) ])
103
- ## ip = p.Popen( ['cmd /c {} 1> {} 2> {} '.format(*text,*logfile) ], stdin=p.PIPE, shell=True )
104
- ## orror(text);
105
- ## ip.stdin.write( text.encode("cp932"))
106
- ## ip.stdin.close()
107
- ## if 1:
108
- ## while ip.poll() is None:
109
- ## time.sleep(0.2)
110
-
111
  while any([False==os.path.exists(f) for f in logfile]):
112
  print("not ready;",[os.path.exists(f) for f in logfile],te)
113
- time.sleep(0.1)
114
  while 1:
115
  ## try:
116
  #with open(logfile[0],"rb") as fo:
@@ -122,11 +114,10 @@ class cltof():
122
  ## print("p;",poll,bit)#lwt
123
  if bit and cb: cb(x+1, vcs(bit))
124
  if poll!=None: break
125
- time.sleep(0.2)
126
  if poll!=None: break
127
  if to<(d:=fppc()):return
128
  ## print(d)
129
- #retcode = ip.wait()
130
  ## except 2: f
131
  if ip.poll()!=None:break
132
  if to<(d:=fppc()):break
@@ -140,8 +131,6 @@ class cltof():
140
  zl.ev.set()
141
  return res
142
  t=th.run(fpin1,(cb,text))
143
- ## jw(t,)
144
- ## time.sleep(1)
145
  return t
146
  @property
147
  def te(zl):
@@ -160,6 +149,9 @@ class cltof():
160
  return zl
161
  @staticmethod
162
  def cbpr(std,b): print(f"{std} cblen({len(b)}) {b}")
 
 
 
163
  def ctof(*w):
164
  p=cltof()
165
  p.ctof(*w)
@@ -214,7 +206,7 @@ def r1reloadFull(dure,me):
214
  timer.start()
215
  ip=p.Popen( me,bufsize=2, stdin=p.PIPE, stdout=p.PIPE,stderr=p.PIPE,shell=True )
216
  while ip.poll() is None:
217
- time.sleep(0.2)
218
  print("while_poll",ip.poll())
219
  pass
220
  ## print(ip.stdout.read())
@@ -240,7 +232,7 @@ if __name__ == '__main__':
240
 
241
  if(c1=="-out"):
242
  for j in fil[2]:
243
- time.sleep(0.3)
244
  sys.stdout.write(j)
245
  if(c1=="-c"):
246
  for f in ":苍天\n:":
@@ -254,7 +246,7 @@ if __name__ == '__main__':
254
  ## input("pw")
255
  sys.stdout.flush()
256
  print("", flush=True)#,file=stdout
257
- time.sleep(1)
258
  if not c1:
259
  print("c1;")
260
  ## reloadFull([r"dir"])
 
4
  import time
5
  from ctypes import *
6
  import subprocess as p
7
+ from wr import *
8
 
9
  def scroll(*ww):
10
  import edit_
 
21
  text="{} 1> {} 2> {} \n".format(text,*logfile)#write
22
  ## orror(text);
23
  ip.stdin.write( text.encode("cp932"))
24
+ shuttown(ip.stdin)
25
  retcode = ip.wait()
26
  #
27
  lir=list(open(f,"rb").read() for f in logfile)
 
41
  if(sh):
42
  text+="\n";
43
  ip.stdin.write( text.encode("cp932"))
44
+ shuttown(ip.stdin)
45
  elif(si):
46
  ip.stdin.write(si)
47
+ shuttown(ip.stdin)
48
 
49
  retcode=None
50
  try:
 
80
  zl.ev=th.Event()
81
  zl.lock=th.Lock()
82
  os.environ['PYTHONIOENCODING'] = 'utf-8'
83
+ def ctof(zl,cb,to, text ,null=""):
84
  from wr import vcs, tp, wfd
85
  zl.ev.clear()
86
  if 0==to:to=3600*12
 
97
  ## ip = p.Popen( [("echo ff"),"1>",logfile[0],"2>",logfile[1]], shell=True )
98
  if isinstance(text,(list,tuple)): te= [*text,"1>",logfile[0],"2>",logfile[1]]
99
  elif isinstance(text,(str)):te= text+" 1> {} 2> {}".format(*logfile)
100
+ if not null or 1:
101
+ zl.ip=ip=p.Popen(text,shell=True, stdout=open(logfile[0],"w"), stderr=open(logfile[1],"w"), stdin=p.PIPE)
102
+ #
 
 
 
 
 
 
 
 
103
  while any([False==os.path.exists(f) for f in logfile]):
104
  print("not ready;",[os.path.exists(f) for f in logfile],te)
105
+ sleep(0.1)
106
  while 1:
107
  ## try:
108
  #with open(logfile[0],"rb") as fo:
 
114
  ## print("p;",poll,bit)#lwt
115
  if bit and cb: cb(x+1, vcs(bit))
116
  if poll!=None: break
117
+ sleep(0.2)
118
  if poll!=None: break
119
  if to<(d:=fppc()):return
120
  ## print(d)
 
121
  ## except 2: f
122
  if ip.poll()!=None:break
123
  if to<(d:=fppc()):break
 
131
  zl.ev.set()
132
  return res
133
  t=th.run(fpin1,(cb,text))
 
 
134
  return t
135
  @property
136
  def te(zl):
 
149
  return zl
150
  @staticmethod
151
  def cbpr(std,b): print(f"{std} cblen({len(b)}) {b}")
152
+ def put(p,te):
153
+ p.ip.stdin.write(te.encode())
154
+ p.ip.stdin.flush()
155
  def ctof(*w):
156
  p=cltof()
157
  p.ctof(*w)
 
206
  timer.start()
207
  ip=p.Popen( me,bufsize=2, stdin=p.PIPE, stdout=p.PIPE,stderr=p.PIPE,shell=True )
208
  while ip.poll() is None:
209
+ sleep(0.2)
210
  print("while_poll",ip.poll())
211
  pass
212
  ## print(ip.stdout.read())
 
232
 
233
  if(c1=="-out"):
234
  for j in fil[2]:
235
+ sleep(0.3)
236
  sys.stdout.write(j)
237
  if(c1=="-c"):
238
  for f in ":苍天\n:":
 
246
  ## input("pw")
247
  sys.stdout.flush()
248
  print("", flush=True)#,file=stdout
249
+ sleep(1)
250
  if not c1:
251
  print("c1;")
252
  ## reloadFull([r"dir"])
wr.py CHANGED
@@ -384,7 +384,17 @@ def catpref(fn,prefix):
384
  def CatPS(fn,p,s):
385
  return catsuff(catpref(fn,p),s)
386
  #
387
- if 1:
 
 
 
 
 
 
 
 
 
 
388
  jwdir=getattr(os.path,b'\x6A\x6F\x69\x6E'.decode())
389
  jofn=jwdir
390
  def jw(te,list):
@@ -396,6 +406,7 @@ if 1:
396
  _lfn="LibFileName"#="lfn"
397
  lfn=os.path
398
  lfnd=lfn.dirname
 
399
  lfnb=lfn.basename
400
  mtime=lfn.getmtime
401
  ctime=lfn.getctime
@@ -404,7 +415,9 @@ if 1:
404
  if isinstance(lis,(dict)): return getattr(lis,b'\x69\x74\x65\x6D\x73'.decode())()
405
  return n12(lis)
406
  sleep=getattr(time,b'\x73\x6C\x65\x65\x70'.decode())
407
-
 
 
408
 
409
 
410
 
@@ -834,9 +847,12 @@ def ttt(p,times=10,interval=4):# try ten times
834
  if n+1 >= times: return e
835
  time.sleep(interval)
836
  continue
 
 
837
  def cbTry(f,ercb=None,lo=0,ww=(),pr=0):
838
  ## flq=1 if hasattr(f, "__self__") and isinstance(f.__self__, orq) else 0
839
  ## la=lambda e: a[1:]
 
840
  @functools.wraps(f)
841
  def cb(*a,**k):
842
  try:
@@ -854,13 +870,17 @@ def cbTry(f,ercb=None,lo=0,ww=(),pr=0):
854
  except Exception as e: # exit is not exception
855
  #except:
856
  et=0
 
 
857
  if ercb: et=cbTry(ercb)(e)
858
  if et:return
859
  if pr: print(except2(0,find=""))
860
  else:
861
- except2(0,find="p",edit="note")
 
862
  ## e2=except2()
863
  ## Mini(te)
 
864
  return cb
865
 
866
  def edipt(te="",find="p",edit=0,fntbl=()):
@@ -1047,8 +1067,8 @@ class puni(dict):
1047
  class pini(puni):
1048
  def __init__(zl,d={},fn="pini00.ini"):
1049
  dict.__init__(zl,d);
1050
- zl.fn=fn;
1051
- if(os.access(fn,os.F_OK)):
1052
  f=rfdv0(fn,["utf-8"])
1053
  for j in f:
1054
  a=j.split("\t");
@@ -1065,8 +1085,9 @@ class pini(puni):
1065
  notTheFormat
1066
  def save(zl):
1067
  te="";
1068
- for k,v in zl.items():
1069
- ti= repr(k) +"\t" +repr(v)+"\n";
 
1070
  te+=ti;
1071
  wfd8(zl.fn,te);#Exceptions during cleanup are always ignored; see the object.__del__() documentation:
1072
  ## deli=__del__#for
@@ -1104,18 +1125,18 @@ class List(list):
1104
  if mo:
1105
  zl.res.append((i,j))
1106
  return zl.res
1107
- def __lt__(zl,o): return zl.append(o)
1108
  def __lshift__(zl,li): return zl.extend(li)
1109
- #def __getitem__(zl,k):
1110
- def getx(zl,k,v):
1111
- return zl.index(k) if k in zl else v
1112
- def u(zl,k,v):
1113
- zl[zl.index(k)]=v
1114
  ## def up(zl,v):
1115
  orList=List
1116
  class ListHash(List):#from collections import OrderedDict
1117
  def put(zl,k,v):#up
1118
- a
1119
  class orLiset(set):#unique list
1120
  pass
1121
  def cmp(zl,ot):
 
384
  def CatPS(fn,p,s):
385
  return catsuff(catpref(fn,p),s)
386
  #
387
+ if "jwdir":
388
+ def lgest(lis):
389
+ l=lis[0]
390
+ for l2 in lis:
391
+ if l2>l: l=l2
392
+ return l
393
+ def notanybad(lis):
394
+ for f in lis:
395
+ if not f: return False
396
+ return True
397
+ #from jwdir import *
398
  jwdir=getattr(os.path,b'\x6A\x6F\x69\x6E'.decode())
399
  jofn=jwdir
400
  def jw(te,list):
 
406
  _lfn="LibFileName"#="lfn"
407
  lfn=os.path
408
  lfnd=lfn.dirname
409
+ lfndir=lfn.dirname
410
  lfnb=lfn.basename
411
  mtime=lfn.getmtime
412
  ctime=lfn.getctime
 
415
  if isinstance(lis,(dict)): return getattr(lis,b'\x69\x74\x65\x6D\x73'.decode())()
416
  return n12(lis)
417
  sleep=getattr(time,b'\x73\x6C\x65\x65\x70'.decode())
418
+ def shuttown(stdin,*w):
419
+ assert hasattr(stdin, b'\x63\x6C\x6F\x73\x65'.decode())
420
+ return getattr(stdin,b'\x63\x6C\x6F\x73\x65'.decode())(*w)
421
 
422
 
423
 
 
847
  if n+1 >= times: return e
848
  time.sleep(interval)
849
  continue
850
+ import th
851
+ cbTryLock=th.Lock()
852
  def cbTry(f,ercb=None,lo=0,ww=(),pr=0):
853
  ## flq=1 if hasattr(f, "__self__") and isinstance(f.__self__, orq) else 0
854
  ## la=lambda e: a[1:]
855
+ counter=0
856
  @functools.wraps(f)
857
  def cb(*a,**k):
858
  try:
 
870
  except Exception as e: # exit is not exception
871
  #except:
872
  et=0
873
+ cb.counter+=1
874
+ if cb.counter>10:return
875
  if ercb: et=cbTry(ercb)(e)
876
  if et:return
877
  if pr: print(except2(0,find=""))
878
  else:
879
+ ## with cbTryLock:#?
880
+ except2(0,find="p",edit="note")
881
  ## e2=except2()
882
  ## Mini(te)
883
+ cb.counter=0
884
  return cb
885
 
886
  def edipt(te="",find="p",edit=0,fntbl=()):
 
1067
  class pini(puni):
1068
  def __init__(zl,d={},fn="pini00.ini"):
1069
  dict.__init__(zl,d);
1070
+ zl.fn=lfn.abspath(fn);
1071
+ if lfn.isfile(fn):
1072
  f=rfdv0(fn,["utf-8"])
1073
  for j in f:
1074
  a=j.split("\t");
 
1085
  notTheFormat
1086
  def save(zl):
1087
  te="";
1088
+ #print(os.getcwd())
1089
+ for f,v in fpn1(zl):
1090
+ ti= repr(f) +"\t" +repr(v)+"\n";
1091
  te+=ti;
1092
  wfd8(zl.fn,te);#Exceptions during cleanup are always ignored; see the object.__del__() documentation:
1093
  ## deli=__del__#for
 
1125
  if mo:
1126
  zl.res.append((i,j))
1127
  return zl.res
1128
+ def __lt__(zl,f): return zl.append(f)
1129
  def __lshift__(zl,li): return zl.extend(li)
1130
+ #def __getitem__(zl,f):
1131
+ def getx(zl,f,v):
1132
+ return zl.index(f) if f in zl else v
1133
+ def u(zl,f,v):
1134
+ zl[zl.index(f)]=v
1135
  ## def up(zl,v):
1136
  orList=List
1137
  class ListHash(List):#from collections import OrderedDict
1138
  def put(zl,k,v):#up
1139
+ 1
1140
  class orLiset(set):#unique list
1141
  pass
1142
  def cmp(zl,ot):