5,597,501 Members 31,370 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
zantekk
Old
(Last edited by zantekk; 10th December 2013 at 01:32 PM.)
#1  
zantekk's Avatar
Senior Member - OP
Thanks Meter 250
Posts: 476
Join Date: Jan 2010
Location: Cologne

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

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.
> HTC One <
> Unocked Bootloader & S-OFF <
> RENOVATE ROM <

follow me @twitter
--
Problem with booting into CWM-Recovery on your HTC One?

Developer for RENOVATE ROM - HTC One
-> Thread | Nightlies <-
The Following 10 Users Say Thank You to zantekk For This Useful Post: [ Click to Expand ]
 
cybojenix
Old
#2  
cybojenix's Avatar
Recognized Developer
Thanks Meter 717
Posts: 610
Join Date: Apr 2012

 
DONATE TO ME
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
Quote:
<cybojenix> Every single language makes sense. They're logical
<cybojenix> Then there's just Perl.
<helicopter88> perl just looks like an esotheric language
<cybojenix> Perl is what came out from those monkeys trying to recreate Shakespeare
<helicopter88> cybojenix, this is the wise sentence of the month

like my work? buy me a present
 

Proud member of TeamHackLG


contact me here
My Builds
P350 kernels: 2.6.35 | 3.0.x
Github
devices: p350 | e610 | Nexus 7 | tegra note 7

The Following User Says Thank You to cybojenix For This Useful Post: [ Click to Expand ]
 
Grondinm
Old
#3  
Grondinm's Avatar
Senior Member
Thanks Meter 233
Posts: 1,158
Join Date: Feb 2008
Location: Moncton
This is great. Thank you. Will be using and might contribute.
Phone: Nexus 5 (32GB)
Rom: SlimKat
Kernel: ElementalX


Tablet: Nexus 7 Flo 32Gb
Rom: CM11/ChaOS
Kernel: Glitch/Stock

Retired Device: Samsung Fascinate(SGH-T959D) &
Xiaomi Mi2 16Gb

Such Donation: DSB9bnVeMhw2RPJbzsP6BQX8uZtXEuUgAo
 
Beatsleigher
Old
#4  
Beatsleigher's Avatar
Senior Member
Thanks Meter 491
Posts: 1,023
Join Date: Oct 2011
Location: Somewhat around here : 52.366848,8.3345

 
DONATE TO ME
Seems like I've started a trend here. Lol
Proud Leader of !


My popular projects on GitHub
Universal Android Toolkit and JDroidLib are now in BETA!


My work (other) work:
"Nothing is infinite, except human stupidity." - Albert Einstein.
"You shouldn't trust everything you see on the internet." - Abraham Lincoln.
 
cybojenix
Old
#5  
cybojenix's Avatar
Recognized Developer
Thanks Meter 717
Posts: 610
Join Date: Apr 2012

 
DONATE TO ME
Quote:
Originally Posted by Beatsleigher View Post
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
Quote:
<cybojenix> Every single language makes sense. They're logical
<cybojenix> Then there's just Perl.
<helicopter88> perl just looks like an esotheric language
<cybojenix> Perl is what came out from those monkeys trying to recreate Shakespeare
<helicopter88> cybojenix, this is the wise sentence of the month

like my work? buy me a present
 

Proud member of TeamHackLG


contact me here
My Builds
P350 kernels: 2.6.35 | 3.0.x
Github
devices: p350 | e610 | Nexus 7 | tegra note 7

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes