Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP zantekk

10th December 2013, 02:21 PM   |  #1  
zantekk's Avatar
OP Senior Member
Flag Cologne
Thanks Meter: 282
 
554 posts
Join Date:Joined: Jan 2010
Donate to Me
More
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 02:32 PM.
The Following 10 Users Say Thank You to zantekk For This Useful Post: [ View ]
17th December 2013, 05:09 PM   |  #2  
cybojenix's Avatar
Recognized Developer / XDA Portal Team
Thanks Meter: 1,717
 
860 posts
Join Date:Joined: Apr 2012
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 ]
17th December 2013, 06:22 PM   |  #3  
Grondinm's Avatar
Senior Member
Flag Moncton
Thanks Meter: 1,459
 
1,529 posts
Join Date:Joined: Feb 2008
Donate to Me
More
This is great. Thank you. Will be using and might contribute.
17th December 2013, 06:34 PM   |  #4  
Beatsleigher's Avatar
Senior Member
Flag Somewhat around here : 52.366848,8.3345
Thanks Meter: 558
 
1,078 posts
Join Date:Joined: Oct 2011
Donate to Me
More
Seems like I've started a trend here. Lol
17th December 2013, 08:34 PM   |  #5  
cybojenix's Avatar
Recognized Developer / XDA Portal Team
Thanks Meter: 1,717
 
860 posts
Join Date:Joined: Apr 2012
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
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes