From f7b30c3129aabb45384c30591ac66f6a1ddab15e Mon Sep 17 00:00:00 2001 From: thelittlefireman Date: Fri, 28 Jul 2017 15:13:45 +0200 Subject: [PATCH 1/8] 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 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 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' ``` --- src/app.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app.py b/src/app.py index de493a2..13372f4 100644 --- a/src/app.py +++ b/src/app.py @@ -11,6 +11,15 @@ from src import log log.init() 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: """ @@ -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') logger.info('Skin destination path: {dst}'.format(dst=skin_dst_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 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)) logger.info('Hardware profile resource path: {rsc}'.format(rsc=profile_src_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 cmd += ' -d {device} -s {skin}'.format(device=device_name_bash, skin=skin_name) From e56eb0e3ab7b0ade504a8cfe67ae96bd778bd01e Mon Sep 17 00:00:00 2001 From: thelittlefireman Date: Fri, 28 Jul 2017 22:45:34 +0200 Subject: [PATCH 2/8] fix : file already exist on start and stop container --- supervisord.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervisord.conf b/supervisord.conf index a4b185b..340e443 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -4,7 +4,7 @@ logfile=%(ENV_LOG_PATH)s/supervisord.log childlogdir=%(ENV_LOG_PATH)s [program:xvfb] -command=/usr/bin/Xvfb %(ENV_DISPLAY)s -screen %(ENV_SCREEN)s %(ENV_SCREEN_WIDTH)sx%(ENV_SCREEN_HEIGHT)sx%(ENV_SCREEN_DEPTH)s +command=rm -r /tmp/ && /usr/bin/Xvfb %(ENV_DISPLAY)s -screen %(ENV_SCREEN)s %(ENV_SCREEN_WIDTH)sx%(ENV_SCREEN_HEIGHT)sx%(ENV_SCREEN_DEPTH)s stdout_logfile=%(ENV_LOG_PATH)s/xvfb.stdout.log stderr_logfile=%(ENV_LOG_PATH)s/xvfb.stderr.log From 486fb5825bc6e9296ac5a504fe951312da813d20 Mon Sep 17 00:00:00 2001 From: thelittlefireman Date: Sat, 29 Jul 2017 22:51:36 +0200 Subject: [PATCH 3/8] fix bad python impl --- src/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app.py b/src/app.py index 13372f4..3c7aaca 100644 --- a/src/app.py +++ b/src/app.py @@ -4,6 +4,7 @@ import json import logging import os import subprocess +import errno from src import CONFIG_FILE, ROOT, CHROME_DRIVER from src import log @@ -14,7 +15,7 @@ logger = logging.getLogger('app') def symlink_force(target, link_name): try: os.symlink(target, link_name) - except OSError, e: + except OSError as e: if e.errno == errno.EEXIST: os.remove(link_name) os.symlink(target, link_name) From e2ad6b75d2a7ff00b63a3b101f58b74957390a71 Mon Sep 17 00:00:00 2001 From: thelittlefireman Date: Mon, 31 Jul 2017 15:12:46 +0200 Subject: [PATCH 4/8] add unit test to symlink_force --- src/tests/unit/test_app.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/tests/unit/test_app.py b/src/tests/unit/test_app.py index 93c555e..8acf3d5 100644 --- a/src/tests/unit/test_app.py +++ b/src/tests/unit/test_app.py @@ -9,6 +9,19 @@ from src import app class TestApp(TestCase): """Unit test class to test other methods in the app.""" + def test_symlink_correct(self): + os.mknod(os.path.join("./","testFile1.txt")) + app.symlink_force(os.path.join("./","testFile1.txt"),os.path.join("./","link_testFile1.txt")) + os.remove(os.path.join("./","testFile1.txt")) + os.remove(os.path.join("./","link_testFile1.txt")) + + """ link already exist""" + def test_symlink_already_exist(self): + os.mknod(os.path.join("./","testFile2.txt")) + os.mknod(os.path.join("./","link_testFile2.txt")) + app.symlink_force(os.path.join("./","testFile2.txt"),os.path.join("./","link_testFile2.txt")) + os.remove(os.path.join("./","testFile2.txt")) + os.remove(os.path.join("./","link_testFile2.txt")) def test_valid_env(self): key = 'ENV_1' From 9d3cb60f41e0f72e1ef2986f1f5bad9180593221 Mon Sep 17 00:00:00 2001 From: thelittlefireman Date: Mon, 31 Jul 2017 15:28:33 +0200 Subject: [PATCH 5/8] add unit test last case --- src/tests/unit/test_app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tests/unit/test_app.py b/src/tests/unit/test_app.py index 8acf3d5..0b74431 100644 --- a/src/tests/unit/test_app.py +++ b/src/tests/unit/test_app.py @@ -9,6 +9,8 @@ from src import app class TestApp(TestCase): """Unit test class to test other methods in the app.""" + + """create symlink""" def test_symlink_correct(self): os.mknod(os.path.join("./","testFile1.txt")) app.symlink_force(os.path.join("./","testFile1.txt"),os.path.join("./","link_testFile1.txt")) @@ -22,6 +24,11 @@ class TestApp(TestCase): app.symlink_force(os.path.join("./","testFile2.txt"),os.path.join("./","link_testFile2.txt")) os.remove(os.path.join("./","testFile2.txt")) os.remove(os.path.join("./","link_testFile2.txt")) + + """test if other exception pop""" + def test_symlink_other_except(self): + with self.assertRaises(Exception): + app.symlink_force(os.path.join("./","testFile3.txt"),os.path.join("./","link_testFile3.txt")) def test_valid_env(self): key = 'ENV_1' From 648010d519dc3f2b064317fbdd982e486bb4ad2e Mon Sep 17 00:00:00 2001 From: thelittlefireman Date: Mon, 31 Jul 2017 15:56:50 +0200 Subject: [PATCH 6/8] delete useless code --- src/app.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app.py b/src/app.py index 3c7aaca..aeaad8a 100644 --- a/src/app.py +++ b/src/app.py @@ -19,8 +19,6 @@ def symlink_force(target, link_name): if e.errno == errno.EEXIST: os.remove(link_name) os.symlink(target, link_name) - else: - raise e def get_or_raise(env: str) -> str: """ From e1d6e3cdbe4446fc393c058549498eb4dd745ff1 Mon Sep 17 00:00:00 2001 From: thelittlefireman Date: Mon, 31 Jul 2017 15:58:38 +0200 Subject: [PATCH 7/8] delete useless code --- src/tests/unit/test_app.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/tests/unit/test_app.py b/src/tests/unit/test_app.py index 0b74431..c94fb04 100644 --- a/src/tests/unit/test_app.py +++ b/src/tests/unit/test_app.py @@ -25,11 +25,6 @@ class TestApp(TestCase): os.remove(os.path.join("./","testFile2.txt")) os.remove(os.path.join("./","link_testFile2.txt")) - """test if other exception pop""" - def test_symlink_other_except(self): - with self.assertRaises(Exception): - app.symlink_force(os.path.join("./","testFile3.txt"),os.path.join("./","link_testFile3.txt")) - def test_valid_env(self): key = 'ENV_1' os.environ[key] = 'test' From 7c48af9b842256704246bbc0744d317b2f51335b Mon Sep 17 00:00:00 2001 From: thelittlefireman Date: Tue, 1 Aug 2017 10:30:04 +0200 Subject: [PATCH 8/8] fix codacy-bot warrning --- src/tests/unit/test_app.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tests/unit/test_app.py b/src/tests/unit/test_app.py index c94fb04..c31ac2d 100644 --- a/src/tests/unit/test_app.py +++ b/src/tests/unit/test_app.py @@ -10,21 +10,23 @@ from src import app class TestApp(TestCase): """Unit test class to test other methods in the app.""" - """create symlink""" + #create symlink + @classmethod def test_symlink_correct(self): os.mknod(os.path.join("./","testFile1.txt")) app.symlink_force(os.path.join("./","testFile1.txt"),os.path.join("./","link_testFile1.txt")) os.remove(os.path.join("./","testFile1.txt")) os.remove(os.path.join("./","link_testFile1.txt")) - """ link already exist""" + #link already exist + @classmethod def test_symlink_already_exist(self): os.mknod(os.path.join("./","testFile2.txt")) os.mknod(os.path.join("./","link_testFile2.txt")) app.symlink_force(os.path.join("./","testFile2.txt"),os.path.join("./","link_testFile2.txt")) os.remove(os.path.join("./","testFile2.txt")) os.remove(os.path.join("./","link_testFile2.txt")) - + def test_valid_env(self): key = 'ENV_1' os.environ[key] = 'test'