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

Commit

Permalink
drop sed and do it in python
Browse files Browse the repository at this point in the history
  • Loading branch information
stoeffel committed Oct 17, 2016
1 parent 1e435ed commit d5aa6df
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions native_package_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import print_function

import collections
import argparse
import collections
import fnmatch
import json
import os
import subprocess
Expand Down Expand Up @@ -141,29 +142,43 @@ def get_source_dirs(vendor_dir, package):
return data['source-directories']


def replace_in_file(filePath, src, target):
""" find replace in a file """
lines = []
with open(filePath) as infile:
for line in infile:
line = line.replace(src, target)
lines.append(line)
with open(filePath, 'w') as outfile:
for line in lines:
outfile.write(line)


def find_all_native_files(path):
""" recursivly find all js files in a package """
native_files = []
for root, dirnames, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, '*.js'):
native_files.append(os.path.join(root, filename))
native_files


def munge_names(vendor_dir, repository, packages):
"""
Replaces the namespaced function names in all native code by the namespace from the given elm-package.json.
"""
namespace, name = namespace_from_repo(repository)
for package in packages:
subprocess.Popen((
"find",
package_dir(vendor_dir, package),
"-type",
"f",
"-exec",
"sed",
"-i",
"",
"-e",
"s/{0}/{1}/g".format(
native_files = []
for root, dirnames, filenames in os.walk(package_dir(vendor_dir, package)):
for filename in fnmatch.filter(filenames, '*.js'):
native_files.append(os.path.join(root, filename))
for native_file in native_files:
replace_in_file(
native_file,
format_native_name(package['namespace'], package['name']),
format_native_name(namespace, name)
),
"{}",
";"
))
)


def update_elm_package(vendor_dir, configs, packages):
Expand Down

0 comments on commit d5aa6df

Please sign in to comment.