Skip to content

Commit

Permalink
Migrate all usages of mkdir and rmdir to buildops (kivy#1668)
Browse files Browse the repository at this point in the history
* Migrate all usages of mkdir and rmdir to buildops

This is a refactor as one step to reduce the size/complexity of the Buildozer class. It doesn't change functionality. except to improve logging consistency and a small performance improvement

* mkdir and rmdir removed from `buildozer/__init__.py`
* All references to buildozer's mkdir and rmdir changed over to use buildops.
* Call to Linux's mkdir via a separate shell replaced with (faster, and platform independent) library call.
* Re-ordered imports, where touched, to match PEP8.

* Make buildops methods more explicit
  • Loading branch information
Julian-O authored and aorizondo committed Aug 28, 2023
1 parent a7c69a3 commit c0c15a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
55 changes: 22 additions & 33 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

__version__ = '1.5.1.dev0'

import codecs
from copy import copy
from fnmatch import fnmatch
import os
from os import environ, unlink, walk, sep, listdir
from os.path import join, exists, dirname, realpath, splitext, expanduser
import re
import sys
from re import search
import select
import codecs
from shutil import copyfile, rmtree, copytree, move, which
from subprocess import Popen, PIPE, TimeoutExpired
import sys
from sys import stdout, stderr, exit
import textwrap
import warnings
from sys import stdout, stderr, exit
from re import search
from os.path import join, exists, dirname, realpath, splitext, expanduser
from subprocess import Popen, PIPE, TimeoutExpired
from os import environ, unlink, walk, sep, listdir, makedirs
from copy import copy
from shutil import copyfile, rmtree, copytree, move, which
from fnmatch import fnmatch

import shlex
import pexpect
Expand All @@ -34,6 +34,7 @@
# on windows, no fcntl
fcntl = None

import buildozer.buildops as buildops
from buildozer.exceptions import BuildozerCommandException
from buildozer.jsonstore import JsonStore
from buildozer.logger import Logger
Expand Down Expand Up @@ -361,22 +362,22 @@ def check_build_layout(self):
exit(1)

# create global dir
self.mkdir(self.global_buildozer_dir)
self.mkdir(self.global_cache_dir)
buildops.mkdir(self.global_buildozer_dir)
buildops.mkdir(self.global_cache_dir)

# create local .buildozer/ dir
self.mkdir(self.buildozer_dir)
buildops.mkdir(self.buildozer_dir)
# create local bin/ dir
self.mkdir(self.bin_dir)
buildops.mkdir(self.bin_dir)

self.mkdir(self.applibs_dir)
buildops.mkdir(self.applibs_dir)
self.state = JsonStore(join(self.buildozer_dir, 'state.db'))

target = self.targetname
if target:
self.mkdir(join(self.global_platform_dir, target, 'platform'))
self.mkdir(join(self.buildozer_dir, target, 'platform'))
self.mkdir(join(self.buildozer_dir, target, 'app'))
buildops.mkdir(join(self.global_platform_dir, target, 'platform'))
buildops.mkdir(join(self.buildozer_dir, target, 'platform'))
buildops.mkdir(join(self.buildozer_dir, target, 'app'))

def check_application_requirements(self):
'''Ensure the application requirements are all available and ready to be
Expand Down Expand Up @@ -410,8 +411,8 @@ def check_application_requirements(self):
return

# recreate applibs
self.rmdir(self.applibs_dir)
self.mkdir(self.applibs_dir)
buildops.rmdir(self.applibs_dir)
buildops.mkdir(self.applibs_dir)

# ok now check the availability of all requirements
for requirement in requirements:
Expand Down Expand Up @@ -464,18 +465,6 @@ def _ensure_virtualenv(self):
self.env_venv['CC'] = '/bin/false'
self.env_venv['CXX'] = '/bin/false'

def mkdir(self, dn):
if exists(dn):
return
self.logger.debug('Create directory {0}'.format(dn))
makedirs(dn)

def rmdir(self, dn):
if not exists(dn):
return
self.logger.debug('Remove directory and subdirectory {}'.format(dn))
rmtree(dn)

def file_matches(self, patterns):
from glob import glob
result = []
Expand Down Expand Up @@ -700,7 +689,7 @@ def _copy_application_sources(self):

# ensure the directory exists
dfn = dirname(rfn)
self.mkdir(dfn)
buildops.mkdir(dfn)

# copy!
self.logger.debug('Copy {0}'.format(sfn))
Expand Down
3 changes: 2 additions & 1 deletion buildozer/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from os.path import join

import buildozer.buildops as buildops
from buildozer.logger import Logger


Expand Down Expand Up @@ -253,7 +254,7 @@ def install_or_update_repo(self, repo, **kwargs):
custom_dir, clone_url, clone_branch = self.path_or_git_url(repo, **kwargs)
if not self.buildozer.file_exists(install_dir):
if custom_dir:
cmd(["mkdir", "-p", install_dir])
buildops.mkdir(install_dir)
cmd(["cp", "-a", f"{custom_dir}/*", f"{install_dir}/"])
else:
cmd(["git", "clone", "--branch", clone_branch, clone_url], cwd=self.buildozer.platform_dir)
Expand Down
3 changes: 2 additions & 1 deletion buildozer/targets/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import plistlib
import sys

import buildozer.buildops as buildops
from buildozer.exceptions import BuildozerCommandException
from buildozer.target import Target, no_config

Expand Down Expand Up @@ -270,7 +271,7 @@ def build_package(self):
ipa = join(self.buildozer.bin_dir, ipa_name)
build_dir = join(self.ios_dir, '{}-ios'.format(app_name.lower()))

self.buildozer.rmdir(intermediate_dir)
buildops.rmdir(intermediate_dir)

self.logger.info('Creating archive...')
self.xcodebuild(
Expand Down

0 comments on commit c0c15a3

Please sign in to comment.