FORUMS
Remove All Ads from XDA

[DEV][WiP][Python3] AndroPy - Library - It's like chatting with your phone!

573 posts
Thanks Meter: 306
 
Post Reply Subscribe to Thread Email Thread
AndroPy
a python3 library to communicate with your phone



INTRODUCTION
Quote:

Hey there! In relation to THIS library written in JAVA I decided to write another library in Python3.
I try to reach the same functionality as that JAVA lib and maybe even more. "Why Python3?" you may ask..
Because it's the language I love the most, it's platform-independent and has got a beautiful syntax.
It's in early stage and there are only some functions working right now which I will explain in another block.


FEATURES
Quote:

  • Install ADB-binary (only working on linux 64-bit for now)
  • Reboot (system, recovery, bootloader)
  • Execute shell commands and get output-lines as a list
  • Get list of connected devices
  • Get build.prop as a dictionary


EXAMPLES
Quote:

I included a function called example wich will be automatically executed if you run adb_util.py.
It shows what you can do with that library. The installer isn't fully working yet, only in Linux 64bit systems.

In order to use adb_util.py the adb-binary has to be in ~/.andropy/bin.


Install adb via installer.py on Linux 64-bit machines
Quote:

Just execute it like:

Code:
python3 installer.py

Show content of /sdcard
Code:
import andropy

with andropy.ADBInterface() as ai:
    print(ai.exec_shell_cmd("ls /sdcard/"))
Get screen-resolution
Code:
import andropy

with andropy.ADBInterface() as ai:
    build_props = ai.get_build_props()
    print(build_props['ro.device.screen_res'])

Samle output from adb_util.py
Code:
marco@mk-think:~/src/andropy$ python3 adb_util.py 
# Welcome to AndroPy #
----------------------
Number of devices detected: 1
Number of your downloaded apps: 41
Your phone's CPU: 1.7 GHz quad-core
Your phone's model: HTC m7ul

SOURCE
Quote:

https://github.com/tehmk/andropy

But as I mentioned it isn't nearly ready yet. Some of you maybe know how to use it in this state.
I will add features and more detailed instructions step by step.

Last edited by zantekk; 10th December 2013 at 01:32 PM.
The Following 10 Users Say Thank You to zantekk For This Useful Post: [ View ] Gift zantekk Ad-Free
 
 
17th December 2013, 04:09 PM |#2  
cybojenix's Avatar
Retired Forum Moderator / Retired Recognized Developer / XDA Portal Team
Thanks Meter: 1,905
 
Donate to Me
More
hey saw this pop up in the portal. after a quick glance this can become a good concept for users, such as timed logs, or a function to dump information (build prop, kmsg, logcat, bugreport, tombstones, you get the idea)

I'd like to bring your attention to this though. the prop parser
Code:
    def get_build_props(self):
        build_props = {}
        out = subprocess.check_output([ADB_EXE, "shell",
                                      "cat /system/build.prop"],
                                      universal_newlines=True)
        self.check_output(out)
        for line in out.split('\n'):
            if line == '':
                continue
            prop = line.split('=')
            if not prop[0].startswith('#'):
                build_props[prop[0]] = prop[1]
        return build_props
you don't need to fetch the whole build prop (for most of the time). this is an extra function that you can use
Code:
def get_prop(self, prop):
    out = subprocess.check_output([ADB_EXE, "shell",
                          "getprop", "{}".format(prop)])
    self.check_output(out)
    return out
if you need any other help or tips, feel free to ping me on freenode, or drop a message here
The Following User Says Thank You to cybojenix For This Useful Post: [ View ] Gift cybojenix Ad-Free
17th December 2013, 05:22 PM |#3  
Grondinm's Avatar
Senior Member
Flag Moncton
Thanks Meter: 1,519
 
Donate to Me
More
This is great. Thank you. Will be using and might contribute.
17th December 2013, 07:34 PM |#5  
cybojenix's Avatar
Retired Forum Moderator / Retired Recognized Developer / XDA Portal Team
Thanks Meter: 1,905
 
Donate to Me
More
Quote:
Originally Posted by Beatsleigher

Seems like I've started a trend here. Lol

seems so. I've got the base layer of a python package that plugs directly into the adb server. none of these wrappers needed
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes