Browse Source

ensured output is linux style;

implemented a saner stat mechanism
seperation
Raphael Roberts 7 years ago
parent
commit
dd1dc77a48
  1. 57
      adb.py

57
adb.py

@ -14,18 +14,6 @@ config = loaded.config
keycodes = loaded.keycodes
exe = config.defaults.exe
exists = '''if [ -e "{file}" ]; then
if [ -d "{file}" ]; then
echo "directory"
elif [ -f "{file}" ]; then
echo "file"
else
echo "error"
fi
else
echo "na"
fi'''
def merge(src, dst,log = False):
if not os.path.exists(dst):
return False
@ -56,7 +44,7 @@ def _adb(*args,output = "shell"):
"buffered": read line by line'''
args = [exe] + list(args)
if output == "out":
return subprocess.check_output(args,shell = False).decode().rstrip('\r\n')
return subprocess.check_output(args,shell = False).decode().replace('\r\n','\n').rstrip()
elif output == "shell":
ret = subprocess.call(args,shell = False)
if ret:
@ -74,7 +62,7 @@ def start_server():
def get_info():
start_server()
thing = _adb("devices","-l",output="out")
formed = list(filter(bool,thing.split("\r\n")))[1:]
formed = list(filter(bool,thing.split("\n")))[1:]
main = {}
for device in formed:
categories = re.split(" +",device)
@ -173,27 +161,48 @@ class ADBWrapper:
class FSActionWrapper(ADBWrapper):
def type(self,file):
e = exists.format(file = file)
res = self.sudo(e,output="out")
return res
def stat(self,file):
'''\
%a Access bits (octal) |%A Access bits (flags)|%b Size/512
%B Bytes per %b (512) |%d Device ID (dec) |%D Device ID (hex)
%f All mode bits (hex) |%F File type |%g Group ID
%G Group name |%h Hard links |%i Inode
%m Mount point |%n Filename |%N Long filename
%o I/O block size |%s Size (bytes) |%t Devtype major (hex)
%T Devtype minor (hex) |%u User ID |%U User name
%x Access time |%X Access unix time |%y File write time
%Y File write unix time|%z Dir change time |%Z Dir change unix time
The valid format escape sequences for filesystems:
%a Available blocks |%b Total blocks |%c Total inodes
%d Free inodes |%f Free blocks |%i File system ID
%l Max filename length |%n File name |%s Fragment size
%S Best transfer size |%t FS type (hex) |%T FS type (driver name)'''
command = 'stat -c "%A;%F;%U;%G" {};echo $?'.format(file)
res = self.sudo(command,output = "out")
output,res = res.split('\n')
if res == '0':
return output.split(';')
def exists(self,file):
return self.type(file) != "na"
return self.stat(file) is not None
def isfile(self,file):
return self.type(file) == 'file'
return self.stat(file)[1] == 'file'
def isdir(self,file):
return self.type(file) == 'directory'
return self.stat(file)[1] == 'directory'
def islink(self,file):
return self.stat(file)[1] == 'symbolic link'
def delete(self,path):
return self.sudo("rm","-rf",path,output="out")
def copy(self,remote,local,del_duplicates = True,ignore_error=True):
remote_type = self.type(remote)
if remote_type != "na":
if remote_type == "directory" and not remote.endswith('/'):
remote_stat = self.stat(remote)
if remote_stat is not None:
if remote_stat[1] == "directory" and not remote.endswith('/'):
remote += '/'
merge_flag = False
if os.path.exists(local):

Loading…
Cancel
Save