fix python error when files already exist
related to : ``` File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main "__main__", mod_spec) File "/usr/lib/python3.5/runpy.py", line 85, in _run_code exec(code, run_globals) File "/root/src/app.py", line 189, in <module> run() File "/root/src/app.py", line 178, in run prepare_avd(device, avd_name) File "/root/src/app.py", line 74, in prepare_avd os.symlink(os.path.join(skin_rsc_path, s), os.path.join(skin_dst_path, s)) FileExistsError: [Errno 17] File exists: '/root/devices/skins/galaxy_nexus' -> '/root/platforms/android-25/skins/galaxy_nexus' Traceback (most recent call last): File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main "__main__", mod_spec) File "/usr/lib/python3.5/runpy.py", line 85, in _run_code exec(code, run_globals) File "/root/src/app.py", line 189, in <module> run() File "/root/src/app.py", line 178, in run prepare_avd(device, avd_name) File "/root/src/app.py", line 74, in prepare_avd os.symlink(os.path.join(skin_rsc_path, s), os.path.join(skin_dst_path, s)) FileExistsError: [Errno 17] File exists: '/root/devices/skins/galaxy_nexus' -> '/root/platforms/android-25/skins/galaxy_nexus' ```
This commit is contained in:
parent
8d544448f1
commit
f7b30c3129
13
src/app.py
13
src/app.py
|
@ -11,6 +11,15 @@ from src import log
|
||||||
log.init()
|
log.init()
|
||||||
logger = logging.getLogger('app')
|
logger = logging.getLogger('app')
|
||||||
|
|
||||||
|
def symlink_force(target, link_name):
|
||||||
|
try:
|
||||||
|
os.symlink(target, link_name)
|
||||||
|
except OSError, e:
|
||||||
|
if e.errno == errno.EEXIST:
|
||||||
|
os.remove(link_name)
|
||||||
|
os.symlink(target, link_name)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
def get_or_raise(env: str) -> str:
|
def get_or_raise(env: str) -> str:
|
||||||
"""
|
"""
|
||||||
|
@ -71,7 +80,7 @@ def prepare_avd(device: str, avd_name: str):
|
||||||
skin_dst_path = os.path.join(ANDROID_HOME, 'platforms', 'android-{api}'.format(api=API_LEVEL), 'skins')
|
skin_dst_path = os.path.join(ANDROID_HOME, 'platforms', 'android-{api}'.format(api=API_LEVEL), 'skins')
|
||||||
logger.info('Skin destination path: {dst}'.format(dst=skin_dst_path))
|
logger.info('Skin destination path: {dst}'.format(dst=skin_dst_path))
|
||||||
for s in os.listdir(skin_rsc_path):
|
for s in os.listdir(skin_rsc_path):
|
||||||
os.symlink(os.path.join(skin_rsc_path, s), os.path.join(skin_dst_path, s))
|
symlink_force(os.path.join(skin_rsc_path, s), os.path.join(skin_dst_path, s))
|
||||||
|
|
||||||
# Hardware and its skin
|
# Hardware and its skin
|
||||||
device_name_bash = device.replace(' ', '\ ')
|
device_name_bash = device.replace(' ', '\ ')
|
||||||
|
@ -85,7 +94,7 @@ def prepare_avd(device: str, avd_name: str):
|
||||||
profile_src_path = os.path.join(ROOT, 'devices', 'profiles', '{profile}.xml'.format(profile=skin_name))
|
profile_src_path = os.path.join(ROOT, 'devices', 'profiles', '{profile}.xml'.format(profile=skin_name))
|
||||||
logger.info('Hardware profile resource path: {rsc}'.format(rsc=profile_src_path))
|
logger.info('Hardware profile resource path: {rsc}'.format(rsc=profile_src_path))
|
||||||
logger.info('Hardware profile destination path: {dst}'.format(dst=profile_dst_path))
|
logger.info('Hardware profile destination path: {dst}'.format(dst=profile_dst_path))
|
||||||
os.symlink(profile_src_path, profile_dst_path)
|
symlink_force(profile_src_path, profile_dst_path)
|
||||||
|
|
||||||
# Append command
|
# Append command
|
||||||
cmd += ' -d {device} -s {skin}'.format(device=device_name_bash, skin=skin_name)
|
cmd += ' -d {device} -s {skin}'.format(device=device_name_bash, skin=skin_name)
|
||||||
|
|
Loading…
Reference in a new issue