Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
add magneto init command
Browse files Browse the repository at this point in the history
  • Loading branch information
maticrivo committed Jun 9, 2015
1 parent d8334be commit 698b95a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
8 changes: 7 additions & 1 deletion magneto/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main(log):


@main.command(context_settings=dict(
ignore_unknown_options=False,
ignore_unknown_options=True,
allow_extra_args=True,
))
@click.argument('tests_path', default='.')
Expand All @@ -82,6 +82,12 @@ def run(ctx, tests_path):
pytest.main(['-sv', tests_path] + ctx.args, plugins=[MagnetoPlugin()])


@main.command()
@click.argument('app', default='no_app')
def init(app):
from .utils import Bootstrap

Bootstrap(app)


if __name__ == '__main__':
Expand Down
33 changes: 31 additions & 2 deletions magneto/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
from multiprocessing import TimeoutError
import signal
import datetime
import os
import subprocess
import time
import urllib
import zipfile
import shutil

import pytest

Expand Down Expand Up @@ -106,7 +110,7 @@ def unlock_device():

# read device screen state
p = ADB.exec_cmd("shell 'if [ -z $(dumpsys power | grep mScreenOn=true) ]; then echo off; else echo on;fi'",
stdout=subprocess.PIPE)
stdout=subprocess.PIPE)
device_screen = p.stdout.readline().strip('\r\n')

if device_screen == 'off':
Expand Down Expand Up @@ -135,4 +139,29 @@ def wait_for_device():
Logger.debug('Waiting for device to finish booting (adb shell getprop sys.boot_completed)')
except TimeoutError:
Logger.debug('Timed out while waiting for sys.boot_completed, there might not be a default launcher set, trying to run anyway')
pass
pass


class Bootstrap(object):
_map = {
'calc': 'https://github.com/EverythingMe/magneto-demo-calc/archive/master.zip'
}

def __init__(self, name):
if name not in self._map:
raise Exception('{} not recognized'.format(name))

filename, headers = urllib.urlretrieve(self._map[name])

with zipfile.ZipFile(filename) as zip_file:
rootdir = zip_file.namelist()[0]
for member in zip_file.namelist()[1:]:
if not os.path.basename(member):
# create dir from zipfile
os.mkdir(os.path.join(os.path.curdir, member.replace(rootdir, '')))
else:
# copy file (taken from zipfile's extract)
source = zip_file.open(member)
target = file(os.path.join(os.path.curdir, member.replace(rootdir, '')), "wb")
with source, target:
shutil.copyfileobj(source, target)

0 comments on commit 698b95a

Please sign in to comment.