Skip to content

Instantly share code, notes, and snippets.

@mjtorn
Created July 1, 2016 10:53
Show Gist options
  • Save mjtorn/212511158914da76463dca361b816952 to your computer and use it in GitHub Desktop.
Save mjtorn/212511158914da76463dca361b816952 to your computer and use it in GitHub Desktop.
Update Freephone2's Fairphone Open git repositories to build sfdroid
#!/usr/bin/env python3
from collections import namedtuple
import concurrent.futures
import os
import subprocess
import sys
DIR = '/home/mjt/src/git_checkouts/fp2/fairphone_os/'
GH = 'https://github.com/smurfy/{}.git'
GIT_REMOTE_CMD = ['git', 'remote', 'add', 'fp2']
GIT_FETCH_CMD = ['git', 'fetch', 'fp2']
GIT_CHECKOUT_CMD = ['git', 'checkout', 'fp2/fp2-sibon']
RepoDir = namedtuple('RepoDir', ('repo', 'dir'))
REPOS_DIRS = (
RepoDir(GH.format('android_hardware_libhardware'), 'hardware/libhardware/'),
RepoDir(GH.format('android_frameworks_native'), 'frameworks/native'),
RepoDir(GH.format('android_frameworks_base'), 'frameworks/base'),
RepoDir(GH.format('android_system_netd'), 'system/netd'),
RepoDir(GH.format('android_frameworks_opt_net_wifi'), 'frameworks/opt/net/wifi'),
RepoDir(GH.format('android_frameworks_opt_net_ethernet'), 'frameworks/opt/net/ethernet'),
# external dbus separately
)
def get_repo(repo_dir):
dir_ = os.path.join(DIR, repo_dir.dir)
cmds = (
GIT_REMOTE_CMD + [repo_dir.repo],
GIT_FETCH_CMD,
GIT_CHECKOUT_CMD,
)
for cmd in cmds:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=dir_)
for line in iter(proc.stdout.read, b''):
sys.stdout.write('[{}] (o) {}\n'.format(proc.pid, line))
sys.stdout.flush()
for line in iter(proc.stderr.read, b''):
sys.stderr.write('[{}] (e) {}\n'.format(proc.pid, line))
sys.stderr.flush()
retval = proc.wait()
if retval != 0 and retval != 128: # ok or repo exists
raise RuntimeError(proc.stderr)
def get_external_dbus():
if not os.path.exists('external'):
os.mkdir('external')
if os.path.exists('external/dbus'):
dir_ = os.path.join(DIR, 'external/dbus')
proc = subprocess.Popen(['git', 'pull'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=dir_)
for line in iter(proc.stdout.read, b''):
sys.stdout.write('[{}] (o) {}\n'.format(proc.pid, line))
sys.stdout.flush()
for line in iter(proc.stderr.read, b''):
sys.stderr.write('[{}] (e) {}\n'.format(proc.pid, line))
sys.stderr.flush()
else:
dir_ = os.path.join(DIR, 'external/')
proc = subprocess.Popen(['git', 'clone', GH.format('android_external_dbus'), 'dbus'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=dir_)
for line in iter(proc.stdout.read, b''):
sys.stdout.write('[{}] (o) {}\n'.format(proc.pid, line))
sys.stdout.flush()
for line in iter(proc.stderr.read, b''):
sys.stderr.write('[{}] (e) {}\n'.format(proc.pid, line))
sys.stderr.flush()
retval = proc.wait()
if retval != 0:
raise RuntimeError(proc.stderr)
def main(args):
if args:
dir_ = args[0]
else:
dir_ = DIR
os.chdir(dir_)
futures = []
with concurrent.futures.ProcessPoolExecutor() as executor:
for repo_dir in REPOS_DIRS:
future = executor.submit(get_repo, repo_dir)
future.add_done_callback(lambda fut: print(fut))
futures.append(future)
for future in futures:
res = future.result()
if res is not None:
print(res)
get_external_dbus()
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment