Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding:utf-8
- """"
- A simple way to manage files in adb with android cellphone
- """
- import subprocess
- import sys
- import csv
- import os
- ORIG_PATH = '/storage/sdcard1/Recordacao'
- OUT_PATH = '/home/reni/files'
- class ClearScreen(object):
- def __init__(self):
- self.clear = self._window if sys.platform.startswith('win') else self._another
- @staticmethod
- def _window():
- os.system('cls')
- @staticmethod
- def _another():
- os.system('clear')
- clear_screen = ClearScreen().clear
- def get_device():
- output = subprocess.Popen('adb devices', shell=True, stdout=subprocess.PIPE).communicate()[0]
- return output.split('\n')[1].split('\t')[0]
- def show_files(device, path):
- output = subprocess.Popen('adb -s {} ls {}'.format(device, path), shell=True, stdout=subprocess.PIPE).communicate()
- output = output[0].split('\n')
- files = [f for f in output if len(f) >= 1]
- clear_screen()
- reader = csv.reader(files, delimiter=' ')
- for _ in range(2):
- reader.next()
- for row in reader:
- yield os.path.join(ORIG_PATH, row[3])
- def copy_photos(files, dev, out_path=OUT_PATH):
- for file in files:
- if file.endswith('.jpg') or file.endswith('.png'):
- filename = os.path.basename(file)
- output = subprocess.Popen('adb -s {} pull {} {}'.format(dev, file, out_path), shell=True, stdout=subprocess.PIPE).communicate()
- print 'transferência de fotos feita!'
- device = get_device()
- files = list(show_files(device, ORIG_PATH))
- copy_photos(files, device)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement