Skip to content

Commit

Permalink
Use own version of pathlib aware shutils.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwa committed Jul 14, 2016
1 parent 000562c commit 10c7055
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
1 change: 0 additions & 1 deletion punic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

def main():
path = Path(sys.argv[0])
print(path.name)
if path.name in set(['carthage_punic']):
carthage_cli()
else:
Expand Down
12 changes: 6 additions & 6 deletions punic/copy_frameworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import os
import re
import shutil
from pathlib2 import Path
from .runner import *
from .logger import *
from .xcode import uuids_from_binary
import punic.shshutil as shutil

def copy_frameworks_main():

Expand Down Expand Up @@ -38,8 +38,8 @@ def copy_frameworks_main():

logger.info('\tCopying framework "{}" to "$SYMROOT/{}"'.format(framework_name, output_path.relative_to(sym_root)))
if output_path.exists():
shutil.rmtree(str(output_path))
shutil.copytree(str(input_path), str(output_path))
shutil.rmtree(output_path)
shutil.copytree(input_path, output_path)

framework_path = output_path

Expand Down Expand Up @@ -88,15 +88,15 @@ def copy_frameworks_main():

logger.info('\tCopying "$PROJECT_DIR/{}" to "$BUILT_PRODUCTS_DIR"'.format(dsym_path.relative_to(project_dir)))
if dsym_output_path.exists():
shutil.rmtree(str(dsym_output_path))
shutil.copytree(str(dsym_path), str(dsym_output_path))
shutil.rmtree(dsym_output_path)
shutil.copytree(dsym_path, dsym_output_path)


# Copy bcsymbolmap files from $PROJECT_DIRCarthage/Build to $BUILT_PRODUCTS_DIR
if enable_bitcode:
for uuid in uuids:
bcsymbolmap_path = punic_builds_dir / (uuid + '.bcsymbolmap')
logger.info('\tCopying "$PROJECT_DIR/{}" to "$BUILT_PRODUCTS_DIR"'.format(bcsymbolmap_path.relative_to(project_dir)))
shutil.copy(str(bcsymbolmap_path), str(built_products_dir))
shutil.copy(bcsymbolmap_path, built_products_dir)


14 changes: 7 additions & 7 deletions punic/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__all__ = ['Punic']

import os
import shutil
import punic.shshutil as shutil
from copy import copy
from pathlib2 import Path
import affirm
Expand Down Expand Up @@ -143,8 +143,8 @@ def build(self, dependencies):

logger.debug('<sub>Copying binary</sub>')
if output_product.product_path.exists():
shutil.rmtree(str(output_product.product_path))
shutil.copytree(str(device_product.product_path), str(output_product.product_path))
shutil.rmtree(output_product.product_path)
shutil.copytree(device_product.product_path, output_product.product_path)

########################################################################################################

Expand All @@ -163,14 +163,14 @@ def build(self, dependencies):
for product in products.values():
for path in product.module_paths:
relative_path = path.relative_to(product.product_path)
shutil.copyfile(str(path), str(output_product.product_path / relative_path))
shutil.copyfile(path, output_product.product_path / relative_path)

########################################################################################################

logger.debug('<sub>Copying bcsymbolmap files</sub>')
for product in products.values():
for path in product.bcsymbolmap_paths:
shutil.copy(str(path), str(output_product.target_build_dir))
shutil.copy(path, output_product.target_build_dir)

########################################################################################################

Expand Down Expand Up @@ -229,8 +229,8 @@ def xcode_projects(self, dependencies=None):
project.checkout(revision)
logger.debug('<sub>Copying project to <ref>Carthage/Checkouts</ref></sub>')
if checkout_path.exists():
shutil.rmtree(str(checkout_path))
shutil.copytree(str(project.path), str(checkout_path), ignore=shutil.ignore_patterns('.git'))
shutil.rmtree(checkout_path)
shutil.copytree(project.path, checkout_path, ignore=shutil.ignore_patterns('.git'))

if not checkout_path.exists():
raise Exception('No checkout at path: {}'.format(checkout_path))
Expand Down
4 changes: 2 additions & 2 deletions punic/punic_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
import os
import shutil
import punic.shshutil as shutil
import sys

import click
Expand Down Expand Up @@ -149,7 +149,7 @@ def clean(context, configuration, platform, xcode, caches):
if caches:
if punic.repo_cache_directory.exists():
logger.info('Cleaning {repo_cache_directory}'.format(**punic.__dict__))
shutil.rmtree(str(punic.repo_cache_directory))
shutil.rmtree(punic.repo_cache_directory)
logger.info('Cleaning run cache')
runner.reset()

Expand Down
18 changes: 18 additions & 0 deletions punic/shshutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import shutil
from pathlib2 import Path

def rmtree(path, ignore_errors=False, onerror=None):
shutil.rmtree(str(path), ignore_errors, onerror)

def copytree(src, dst, symlinks=False, ignore=None):
shutil.copytree(str(src), str(dst), symlinks, ignore)

def copy(src, dst):
shutil.copy(str(src), str(dst))

def copyfile(src, dst):
shutil.copyfile(str(src), str(dst))

def ignore_patterns(*patterns):
return shutil.ignore_patterns(*patterns)

0 comments on commit 10c7055

Please sign in to comment.