Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show envs when run2 #802

Merged
merged 3 commits into from
Feb 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import os
import re
import sys
import zipfile
import select
import codecs
import textwrap
Expand All @@ -24,6 +23,9 @@
from copy import copy
from shutil import copyfile, rmtree, copytree, move
from fnmatch import fnmatch

from pprint import pformat

try:
from urllib.request import FancyURLopener
from configparser import SafeConfigParser
Expand All @@ -41,7 +43,7 @@
colorama.init()

RESET_SEQ = colorama.Fore.RESET + colorama.Style.RESET_ALL
COLOR_SEQ = lambda x: x
COLOR_SEQ = lambda x: x # noqa: E731
BOLD_SEQ = ''
if sys.platform == 'win32':
BLACK = colorama.Fore.BLACK + colorama.Style.DIM
Expand All @@ -54,7 +56,7 @@
except ImportError:
if sys.platform != 'win32':
RESET_SEQ = "\033[0m"
COLOR_SEQ = lambda x: "\033[1;{}m".format(30 + x)
COLOR_SEQ = lambda x: "\033[1;{}m".format(30 + x) # noqa: E731
BOLD_SEQ = "\033[1m"
BLACK = 0
RED = 1
Expand All @@ -73,11 +75,13 @@
SIMPLE_HTTP_SERVER_PORT = 8000
IS_PY3 = sys.version_info[0] >= 3


class ChromeDownloader(FancyURLopener):
version = (
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36')


urlretrieve = ChromeDownloader().retrieve


Expand All @@ -99,6 +103,10 @@ class BuildozerCommandException(BuildozerException):

class Buildozer(object):

ERROR = 0
INFO = 1
DEBUG = 2

standard_cmds = ('distclean', 'update', 'debug', 'release',
'deploy', 'run', 'serve')

Expand Down Expand Up @@ -132,7 +140,7 @@ def __init__(self, filename='buildozer.spec', target=None):
try:
self.log_level = int(self.config.getdefault(
'buildozer', 'log_level', '1'))
except:
except Exception:
pass

build_dir = self.config.getdefault('buildozer', 'builddir', None)
Expand All @@ -158,7 +166,7 @@ def set_target(self, target):
target = self.translate_target(target)
self.targetname = target
m = __import__('buildozer.targets.{0}'.format(target),
fromlist=['buildozer'])
fromlist=['buildozer'])
self.target = m.get_target(self)
self.check_build_layout()
self.check_configuration_tokens()
Expand Down Expand Up @@ -231,13 +239,19 @@ def log(self, level, msg):
print('{} {}'.format(LOG_LEVELS_T[level], msg))

def debug(self, msg):
self.log(2, msg)
self.log(self.DEBUG, msg)

def log_env(self, level, env):
"""dump env into debug logger in readable format"""
self.log(level, "ENVIRONMENT:")
for k, v in env.items():
self.log(level, " {} = {}".format(k, pformat(v)))

def info(self, msg):
self.log(1, msg)
self.log(self.INFO, msg)

def error(self, msg):
self.log(0, msg)
self.log(self.ERROR, msg)

#
# Internal check methods
Expand Down Expand Up @@ -282,6 +296,7 @@ def cmd(self, command, **kwargs):
else:
self.debug('Run {0!r} ...'.format(command.split()[0]))
self.debug('Cwd {}'.format(kwargs.get('cwd')))
self.log_env(self.DEBUG, kwargs["env"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that like should be removed.
I'm seeing it only now after using buildozer master for a while.
For instance during the auto accept license process, this log_env seems to be printing every time. We want it only after crashes, not for every command call

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a PR to remove that line #843


# open the process
if sys.platform == 'win32':
Expand Down Expand Up @@ -335,9 +350,10 @@ def cmd(self, command, **kwargs):
process.communicate()
if process.returncode != 0 and break_on_error:
self.error('Command failed: {0}'.format(command))
self.log_env(self.ERROR, kwargs['env'])
self.error('')
self.error('Buildozer failed to execute the last command')
if self.log_level <= 1:
if self.log_level <= self.INFO:
self.error('If the error is not obvious, please raise the log_level to 2')
self.error('and retry the latest command.')
else:
Expand Down Expand Up @@ -406,10 +422,10 @@ def check_configuration_tokens(self):
adderror('[app] One of "version" or "version.regex" must be set')
if version and version_regex:
adderror('[app] Conflict between "version" and "version.regex"'
', only one can be used.')
', only one can be used.')
if version_regex and not get('app', 'version.filename', ''):
adderror('[app] "version.filename" is missing'
', required by "version.regex"')
', required by "version.regex"')

orientation = get('app', 'orientation', 'landscape')
if orientation not in ('landscape', 'portrait', 'all', 'sensorLandscape'):
Expand Down Expand Up @@ -482,9 +498,9 @@ def check_application_requirements(self):
return

# remove all the requirements that the target can compile
onlyname = lambda x: x.split('==')[0]
onlyname = lambda x: x.split('==')[0] # noqa: E731
requirements = [x for x in requirements if onlyname(x) not in
target_available_packages]
target_available_packages]

if requirements and hasattr(sys, 'real_prefix'):
e = self.error
Expand All @@ -496,7 +512,7 @@ def check_application_requirements(self):

# did we already installed the libs ?
if exists(self.applibs_dir) and \
self.state.get('cache.applibs', '') == requirements:
self.state.get('cache.applibs', '') == requirements:
self.debug('Application requirements already installed, pass')
return

Expand Down