Skip to content

Commit

Permalink
Merge pull request #486 from AndreMiras/feature/find_xcodeproj_helper
Browse files Browse the repository at this point in the history
DRY via the find_xcodeproj() helper method
  • Loading branch information
AndreMiras authored May 6, 2020
2 parents 9c68080 + 04b82d8 commit efd47e6
Showing 1 changed file with 17 additions and 36 deletions.
53 changes: 17 additions & 36 deletions kivy_ios/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@
from pprint import pformat
import logging
from urllib.request import FancyURLopener, urlcleanup
from pbxproj import XcodeProject
from pbxproj.pbxextensions.ProjectFiles import FileOptions

try:
from pbxproj import XcodeProject
from pbxproj.pbxextensions.ProjectFiles import FileOptions
except ImportError:
print("ERROR: Python requirements are missing")
print("To install: pip install -r requirements.txt")
sys.exit(1)
curdir = dirname(__file__)


Expand Down Expand Up @@ -1241,6 +1236,18 @@ def __init__(self):
exit(1)
getattr(self, args.command)()

@staticmethod
def find_xcodeproj(filename):
if not filename.endswith(".xcodeproj"):
# try to find the xcodeproj
from glob import glob
xcodeproj = glob(join(filename, "*.xcodeproj"))
if not xcodeproj:
logger.error("Unable to find a xcodeproj in {}".format(filename))
sys.exit(1)
filename = xcodeproj[0]
return filename

def build(self):
ctx = Context()
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -1385,16 +1392,7 @@ def update(self):
parser.add_argument("--add-framework", action="append", help="Additional Frameworks to include with this project")
args = parser.parse_args(sys.argv[2:])

filename = args.filename
if not filename.endswith(".xcodeproj"):
# try to find the xcodeproj
from glob import glob
xcodeproj = glob(join(filename, "*.xcodeproj"))
if not xcodeproj:
logger.error("Unable to find a xcodeproj in {}".format(filename))
sys.exit(1)
filename = xcodeproj[0]

filename = self.find_xcodeproj(args.filename)
filename = join(filename, "project.pbxproj")
if not exists(filename):
logger.error("{} not found".format(filename))
Expand Down Expand Up @@ -1468,15 +1466,7 @@ def xcode(self):
parser = argparse.ArgumentParser(description="Open the xcode project")
parser.add_argument("filename", help="Path to your project or xcodeproj")
args = parser.parse_args(sys.argv[2:])
filename = args.filename
if not filename.endswith(".xcodeproj"):
# try to find the xcodeproj
from glob import glob
xcodeproj = glob(join(filename, "*.xcodeproj"))
if not xcodeproj:
logger.error("Unable to find a xcodeproj in {}".format(filename))
sys.exit(1)
filename = xcodeproj[0]
filename = self.find_xcodeproj(args.filename)
sh.open(filename)

def _xcassets(self, title, command):
Expand All @@ -1490,16 +1480,7 @@ def _xcassets(self, title, command):
logger.error("image path does not exists.")
return

filename = args.filename
if not filename.endswith(".xcodeproj"):
# try to find the xcodeproj
from glob import glob
xcodeproj = glob(join(filename, "*.xcodeproj"))
if not xcodeproj:
logger.error("Unable to find a xcodeproj in {}".format(filename))
sys.exit(1)
filename = xcodeproj[0]

filename = self.find_xcodeproj(args.filename)
project_name = filename.split("/")[-1].replace(".xcodeproj", "")
images_xcassets = realpath(join(filename, "..", project_name,
"Images.xcassets"))
Expand Down

0 comments on commit efd47e6

Please sign in to comment.