Advertisement
renix1

Android Manager

Nov 16th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. # coding:utf-8
  2. """"
  3.    A simple way to manage files in adb with android cellphone
  4. """
  5. import subprocess
  6. import sys
  7. import csv
  8. import os
  9.  
  10.  
  11. ORIG_PATH = '/storage/sdcard1/Recordacao'
  12. OUT_PATH = '/home/reni/files'
  13.  
  14.  
  15. class ClearScreen(object):
  16.     def __init__(self):
  17.         self.clear = self._window if sys.platform.startswith('win') else self._another
  18.  
  19.     @staticmethod
  20.     def _window():
  21.         os.system('cls')
  22.  
  23.     @staticmethod
  24.     def _another():
  25.         os.system('clear')
  26.  
  27.  
  28. clear_screen = ClearScreen().clear
  29.  
  30.  
  31. def get_device():
  32.     output = subprocess.Popen('adb devices', shell=True, stdout=subprocess.PIPE).communicate()[0]
  33.     return output.split('\n')[1].split('\t')[0]
  34.  
  35.  
  36. def show_files(device, path):
  37.     output = subprocess.Popen('adb -s {} ls {}'.format(device, path), shell=True, stdout=subprocess.PIPE).communicate()
  38.     output = output[0].split('\n')
  39.     files = [f for f in output if len(f) >= 1]
  40.     clear_screen()
  41.     reader = csv.reader(files, delimiter=' ')
  42.     for _ in range(2):
  43.         reader.next()
  44.     for row in reader:
  45.         yield os.path.join(ORIG_PATH, row[3])
  46.  
  47. def copy_photos(files, dev, out_path=OUT_PATH):
  48.     for file in files:
  49.         if file.endswith('.jpg') or file.endswith('.png'):
  50.             filename = os.path.basename(file)
  51.             output = subprocess.Popen('adb -s {} pull {} {}'.format(dev, file, out_path), shell=True, stdout=subprocess.PIPE).communicate()
  52.     print 'transferência de fotos feita!'
  53.  
  54. device = get_device()
  55. files = list(show_files(device, ORIG_PATH))
  56. copy_photos(files, device)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement