From a78d633abf361a3f535813a509fdf23ce19e2a83 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Sun, 29 May 2016 05:13:10 +0530 Subject: [PATCH 01/33] created unique list of failures using set --- swc-installation-test-2.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index bd7960d..923601e 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -274,12 +274,10 @@ def check(checks=None): version or 'unknown')) if failures: print('\nFailures:') - printed = [] + failures = list(set(failures)) for failure in failures: - if failure not in printed: - print() - print(failure) - printed.append(failure) + print() + print(failure) return False return True From 22d8dbe22803f4b041398d91b5fbc9be1de5624c Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Sun, 29 May 2016 05:22:29 +0530 Subject: [PATCH 02/33] created a list of failures containing name and version --- swc-installation-test-2.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 923601e..71fb2c0 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -250,6 +250,7 @@ def __str__(self): def check(checks=None): successes = [] failures = [] + failure_messages = [] if not checks: checks = CHECKS for check in checks: @@ -261,8 +262,9 @@ def check(checks=None): try: version = checker.check() except DependencyError as e: - failures.append(e) + failure_messages.append(e) _sys.stdout.write('fail\n') + failures.append((checker, version)) else: _sys.stdout.write('pass\n') successes.append((checker, version)) @@ -275,7 +277,8 @@ def check(checks=None): if failures: print('\nFailures:') failures = list(set(failures)) - for failure in failures: + failure_messages = list(set(failure_messages)) + for failure in failure_messages: print() print(failure) return False From 77a5925aa897a136457605d7912e86cc967c32ba Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Tue, 31 May 2016 17:34:06 +0530 Subject: [PATCH 03/33] Added a function for sending the data to server --- swc-installation-test-2.py | 44 ++++++++++++++++++++++++++++++++++---- test.py | 15 +++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 test.py diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 71fb2c0..e50f724 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -277,12 +277,12 @@ def check(checks=None): if failures: print('\nFailures:') failures = list(set(failures)) - failure_messages = list(set(failure_messages)) + failure_messages = set(failure_messages) for failure in failure_messages: print() print(failure) - return False - return True + return (False, successes, failures) + return (True, successes, failures) class Dependency (object): @@ -1011,6 +1011,41 @@ def print_suggestions(instructor_fallback=True): print('For help, email the *entire* output of this script to') print('your instructor.') +def send_to_server(successes_list, failures_list): + """ + This function sends the details of failures and successes to server. + + """ + import json + try: + import httplib as http_client + except ImportError: + import http.client as http_client + HOST = "127.0.0.1:5000" + endpoint = "/installation_data/" + successful_installs = [] + failed_installs = [] + for checker, version in successes_list: + successful_installs.append({"name": checker.full_name(), + "version": version}) + for checker, version in failures_list: + failed_installs.append({"name": checker.full_name(), + "version": version}) + user_system_info = {} + headers = {"Content-Type": "application/json"} + data = {"successful_installs" : successful_installs, + "failed_installs" : failed_installs, "user_system_info":user_system_info} + data = json.dumps(data) + conn = http_client.HTTPConnection(HOST) + print("\nPushing the data to server....\n") + try: + conn.request("POST", endpoint, data, headers=headers) + response = conn.getresponse() + except: + print("\nConnection could not be established with server!") + + print(response.read()) + conn.close() if __name__ == '__main__': import optparse as _optparse @@ -1024,7 +1059,8 @@ def print_suggestions(instructor_fallback=True): 'installation issues')) options,args = parser.parse_args() try: - passed = check(args) + passed, successes_list, failures_list = check(args) + send_to_server(successes_list, failures_list) # Push data to server except InvalidCheck as e: print("I don't know how to check for {0!r}".format(e.check)) print('I do know how to check for:') diff --git a/test.py b/test.py new file mode 100644 index 0000000..6ed2b43 --- /dev/null +++ b/test.py @@ -0,0 +1,15 @@ +class A: + def __init__(self, message): + self.message = message + # self.a = (("message",['sdsd','sdsdd']), (2,3)) + + # def __repr__(self): + # return self.message + def __iter__(self): + a = ((3,9), (5,6)) + return iter(a) + def __getitem__(self): + a = {"dfdf":"dfdfdf"} + return a + +print dict(A("Hello")) From d2683e94271e18b531533bf734a7abe1720cd8dc Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Wed, 1 Jun 2016 23:14:18 +0530 Subject: [PATCH 04/33] Added Unique key constraint while sending data to server to identify the user --- .gitignore | 1 + swc-installation-test-2.py | 24 +++++++++++++++++++++--- test.py | 15 --------------- 3 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 .gitignore delete mode 100644 test.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0e6d8b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +key.txt \ No newline at end of file diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index e50f724..e7770ec 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -1017,12 +1017,25 @@ def send_to_server(successes_list, failures_list): """ import json + import datetime try: import httplib as http_client except ImportError: import http.client as http_client HOST = "127.0.0.1:5000" endpoint = "/installation_data/" + + try: + with open('key.txt', 'r') as f: + first_line = f.readline() + unique_id = first_line.split("[key:]")[1] + date = first_line.split("[key:]")[0] + if date != str(datetime.date.today()): + unique_id = None + except Exception,e: + print(str(e)) + unique_id = None + successful_installs = [] failed_installs = [] for checker, version in successes_list: @@ -1034,17 +1047,22 @@ def send_to_server(successes_list, failures_list): user_system_info = {} headers = {"Content-Type": "application/json"} data = {"successful_installs" : successful_installs, - "failed_installs" : failed_installs, "user_system_info":user_system_info} + "failed_installs" : failed_installs, "user_system_info":user_system_info, + "unique_user_id" : unique_id} data = json.dumps(data) conn = http_client.HTTPConnection(HOST) print("\nPushing the data to server....\n") try: conn.request("POST", endpoint, data, headers=headers) response = conn.getresponse() + response_string = response.read() + print(response_string) + response = json.loads(response_string) + unique_id = response.get("key") + file = open('key.txt', 'w+') + file.write(str(datetime.date.today()) + "[key:]" + unique_id) except: print("\nConnection could not be established with server!") - - print(response.read()) conn.close() if __name__ == '__main__': diff --git a/test.py b/test.py deleted file mode 100644 index 6ed2b43..0000000 --- a/test.py +++ /dev/null @@ -1,15 +0,0 @@ -class A: - def __init__(self, message): - self.message = message - # self.a = (("message",['sdsd','sdsdd']), (2,3)) - - # def __repr__(self): - # return self.message - def __iter__(self): - a = ((3,9), (5,6)) - return iter(a) - def __getitem__(self): - a = {"dfdf":"dfdfdf"} - return a - -print dict(A("Hello")) From 3a36b6322d86f593ecaaecf34a3dadcf766de5bd Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Tue, 7 Jun 2016 14:49:31 +0530 Subject: [PATCH 05/33] Changed HOST to global Variable --- swc-installation-test-2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index e7770ec..4bdc9de 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -79,6 +79,7 @@ def import_module(name): __version__ = '0.1' +HOST = "127.0.0.1:5000" # Comment out any entries you don't need CHECKS = [ @@ -1022,7 +1023,7 @@ def send_to_server(successes_list, failures_list): import httplib as http_client except ImportError: import http.client as http_client - HOST = "127.0.0.1:5000" + endpoint = "/installation_data/" try: From 393b3172fa8ac73c2d77e146f15d7297c06a83d6 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Tue, 7 Jun 2016 15:31:09 +0530 Subject: [PATCH 06/33] Added system information to request --- swc-installation-test-2.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 4bdc9de..384d7b1 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -1045,7 +1045,20 @@ def send_to_server(successes_list, failures_list): for checker, version in failures_list: failed_installs.append({"name": checker.full_name(), "version": version}) - user_system_info = {} + # User's System information : + distribution_name = _platform.linux_distribution()[0] + distribution_version = _platform.linux_distribution()[1] + system = _platform.system() + system_version = _platform.version() + machine = _platform.machine() + system_platform = _platform.platform() + python_version = _platform.python_version() + + user_system_info = {"distribution_name": distribution_name, + "distribution_version" : distribution_version, + "system" : system, "system_version" : system_version, + "machine" : machine, "system_platform" : system_platform, + "python_version" : python_version } headers = {"Content-Type": "application/json"} data = {"successful_installs" : successful_installs, "failed_installs" : failed_installs, "user_system_info":user_system_info, From c9d73f7c583ac74ddeadde5dc3e49063bd27e329 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Tue, 7 Jun 2016 16:10:19 +0530 Subject: [PATCH 07/33] Handled response error messages --- swc-installation-test-2.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 384d7b1..9721137 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -1034,7 +1034,6 @@ def send_to_server(successes_list, failures_list): if date != str(datetime.date.today()): unique_id = None except Exception,e: - print(str(e)) unique_id = None successful_installs = [] @@ -1053,7 +1052,7 @@ def send_to_server(successes_list, failures_list): machine = _platform.machine() system_platform = _platform.platform() python_version = _platform.python_version() - + user_system_info = {"distribution_name": distribution_name, "distribution_version" : distribution_version, "system" : system, "system_version" : system_version, @@ -1070,11 +1069,16 @@ def send_to_server(successes_list, failures_list): conn.request("POST", endpoint, data, headers=headers) response = conn.getresponse() response_string = response.read() - print(response_string) - response = json.loads(response_string) - unique_id = response.get("key") - file = open('key.txt', 'w+') - file.write(str(datetime.date.today()) + "[key:]" + unique_id) + # print(response_string) + if response.status == 200: + print("\nSuccessfully Pushed to Server!") + response = json.loads(response_string) + unique_id = response.get("key") + file = open('key.txt', 'w+') + file.write(str(datetime.date.today()) + "[key:]" + unique_id) + else: + print("\nSomething bad happened at Server!") + except: print("\nConnection could not be established with server!") conn.close() From 6c244b5e309479504ce4cfddc43abfbe815f6931 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Thu, 9 Jun 2016 21:26:43 +0530 Subject: [PATCH 08/33] added error description to the failure list --- swc-installation-test-2.py | 58 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 9721137..7e0fa1a 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -17,26 +17,26 @@ python swc-installation-test-2.py git virtual-editor -This is useful if the original test told you to install a more recent -version of a particular dependency, and you just want to re-test that -dependency. -""" - -# Some details about the implementation: - -# The dependencies are divided into a hierarchy of classes rooted on -# Dependency class. You can refer to the code to see which package -# comes under which type of dependency. - -# The CHECKER dictionary stores information about all the dependencies -# and CHECKS stores list of the dependencies which are to be checked in -# the current workshop. - -# In the "__name__ == '__main__'" block, we launch all the checks with -# check() function, which prints information about the tests as they run -# and details about the failures after the tests complete. In case of -# failure, the functions print_system_info() and print_suggestions() -# are called after this, where the former prints information about the + This is useful if the original test told you to install a more recent + version of a particular dependency, and you just want to re-test that + dependency. + """ + + # Some details about the implementation: + + # The dependencies are divided into a hierarchy of classes rooted on + # Dependency class. You can refer to the code to see which package + # comes under which type of dependency. + + # The CHECKER dictionary stores information about all the dependencies + # and CHECKS stores list of the dependencies which are to be checked in + # the current workshop. + + # In the "__name__ == '__main__'" block, we launch all the checks with + # check() function, which prints information about the tests as they run + # and details about the failures after the tests complete. In case of + # failure, the functions print_system_info() and print_suggestions() + # are called after this, where the former prints information about the # user's system for debugging purposes while the latter prints some # suggestions to follow. @@ -233,6 +233,10 @@ def get_url(self): return url return self._default_url + def get_data(self): + data = {"error_description" : self.message} + return data + def __str__(self): url = self.get_url() lines = [ @@ -265,7 +269,9 @@ def check(checks=None): except DependencyError as e: failure_messages.append(e) _sys.stdout.write('fail\n') - failures.append((checker, version)) + e_data = e.get_data() + failures.append({"name": checker.full_name(), "version" : version, + "error_description": e_data.get('error_description')}) else: _sys.stdout.write('pass\n') successes.append((checker, version)) @@ -277,7 +283,6 @@ def check(checks=None): version or 'unknown')) if failures: print('\nFailures:') - failures = list(set(failures)) failure_messages = set(failure_messages) for failure in failure_messages: print() @@ -1037,14 +1042,10 @@ def send_to_server(successes_list, failures_list): unique_id = None successful_installs = [] - failed_installs = [] + failed_installs = failures_list for checker, version in successes_list: successful_installs.append({"name": checker.full_name(), "version": version}) - for checker, version in failures_list: - failed_installs.append({"name": checker.full_name(), - "version": version}) - # User's System information : distribution_name = _platform.linux_distribution()[0] distribution_version = _platform.linux_distribution()[1] system = _platform.system() @@ -1077,8 +1078,7 @@ def send_to_server(successes_list, failures_list): file = open('key.txt', 'w+') file.write(str(datetime.date.today()) + "[key:]" + unique_id) else: - print("\nSomething bad happened at Server!") - + print("\nSomething bad happened at Server!") except: print("\nConnection could not be established with server!") conn.close() From 528b4c456be13d3150d665d3594f826160b88d79 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Tue, 14 Jun 2016 18:57:06 +0530 Subject: [PATCH 09/33] changed host name --- swc-installation-test-2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 7e0fa1a..36d3fdb 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -79,7 +79,8 @@ def import_module(name): __version__ = '0.1' -HOST = "127.0.0.1:5000" +# HOST = "127.0.0.1:5000" +HOST = "installation.software-carpentry.org" # Comment out any entries you don't need CHECKS = [ From f8254ee4283160ff61575a0659d95c3fa4314eae Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Thu, 16 Jun 2016 19:12:48 +0530 Subject: [PATCH 10/33] Fixed unknwon version for failures, and 'the JSON object must be str' error in python 3 --- swc-installation-test-2.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 36d3fdb..d141ec6 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -79,8 +79,8 @@ def import_module(name): __version__ = '0.1' -# HOST = "127.0.0.1:5000" -HOST = "installation.software-carpentry.org" +HOST = "127.0.0.1:5000" +# HOST = "installation.software-carpentry.org" # Comment out any entries you don't need CHECKS = [ @@ -268,6 +268,8 @@ def check(checks=None): try: version = checker.check() except DependencyError as e: + if version not in locals() or version is None: + version = "unknown" failure_messages.append(e) _sys.stdout.write('fail\n') e_data = e.get_data() @@ -1039,7 +1041,7 @@ def send_to_server(successes_list, failures_list): date = first_line.split("[key:]")[0] if date != str(datetime.date.today()): unique_id = None - except Exception,e: + except: unique_id = None successful_installs = [] @@ -1074,7 +1076,7 @@ def send_to_server(successes_list, failures_list): # print(response_string) if response.status == 200: print("\nSuccessfully Pushed to Server!") - response = json.loads(response_string) + response = json.loads(response_string.decode('utf-8')) unique_id = response.get("key") file = open('key.txt', 'w+') file.write(str(datetime.date.today()) + "[key:]" + unique_id) From 8f2d340989a2af60b66b4982e8386df1337ec88b Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Sat, 18 Jun 2016 05:12:06 +0530 Subject: [PATCH 11/33] fixed error for unknown version --- swc-installation-test-2.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index d141ec6..291699f 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -117,10 +117,10 @@ def import_module(name): 'scipy', 'matplotlib', 'pandas', - #'sympy', - #'Cython', - #'networkx', - #'mayavi.mlab', + # 'sympy', + # 'Cython', + # 'networkx', + # 'mayavi.mlab', ] CHECKER = {} @@ -268,7 +268,7 @@ def check(checks=None): try: version = checker.check() except DependencyError as e: - if version not in locals() or version is None: + if 'version' not in locals() or version is None: version = "unknown" failure_messages.append(e) _sys.stdout.write('fail\n') From f51872da97cfc079a32a0cd52b23bef20fe7d9b8 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Sun, 19 Jun 2016 05:29:04 +0530 Subject: [PATCH 12/33] Users are given the option to enter their email id and workshop id. Also, if anytime the script is terminated using ctrl+Z or ctrl+C, data is still pushed to server --- swc-installation-test-2.py | 61 +++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 291699f..ba053af 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -1025,8 +1025,7 @@ def send_to_server(successes_list, failures_list): This function sends the details of failures and successes to server. """ - import json - import datetime + import json, signal, sys, datetime try: import httplib as http_client except ImportError: @@ -1066,25 +1065,47 @@ def send_to_server(successes_list, failures_list): data = {"successful_installs" : successful_installs, "failed_installs" : failed_installs, "user_system_info":user_system_info, "unique_user_id" : unique_id} - data = json.dumps(data) - conn = http_client.HTTPConnection(HOST) - print("\nPushing the data to server....\n") + + def senddata(): + final_data = json.dumps(data) + conn = http_client.HTTPConnection(HOST) + print("\nPushing the data to server....\n") + try: + conn.request("POST", endpoint, final_data, headers=headers) + response = conn.getresponse() + response_string = response.read() + # print(response_string) + if response.status == 200: + print("\nSuccessfully Pushed to Server!") + response = json.loads(response_string.decode('utf-8')) + unique_id = response.get("key") + file = open('key.txt', 'w+') + file.write(str(datetime.date.today()) + "[key:]" + unique_id) + else: + print("\nSomething bad happened at Server!") + except: + print("\nConnection could not be established with server!") + conn.close() + def handler(signum, frame): # captures ctrl+z + senddata() + sys.exit(0) + signal.signal(signal.SIGTSTP, handler) try: - conn.request("POST", endpoint, data, headers=headers) - response = conn.getresponse() - response_string = response.read() - # print(response_string) - if response.status == 200: - print("\nSuccessfully Pushed to Server!") - response = json.loads(response_string.decode('utf-8')) - unique_id = response.get("key") - file = open('key.txt', 'w+') - file.write(str(datetime.date.today()) + "[key:]" + unique_id) - else: - print("\nSomething bad happened at Server!") - except: - print("\nConnection could not be established with server!") - conn.close() + global input + try: + input = raw_input + except NameError: + pass + choice = input("\nPlease share your email id and workshop_id with us " \ + "to improve our scripts.\nAre you in ? (y/n) :") + if choice == 'y' or choice == 'Y': + email = input("Please Enter your email id: ") + data['user_system_info']['email_id'] = email + workshop_id = input("Please Enter the workshop id: ") + data['user_system_info']['workshop_id'] = workshop_id + senddata() + except KeyboardInterrupt: #for catching ctrl+c + senddata() if __name__ == '__main__': import optparse as _optparse From 9f1680e46e2cc941200ccfcda81320e99e3ccf75 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Wed, 22 Jun 2016 23:38:06 +0530 Subject: [PATCH 13/33] Removed keyboard interrupt handling because of issues in windows platform --- swc-installation-test-2.py | 80 +++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index ba053af..1a1832c 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -273,8 +273,11 @@ def check(checks=None): failure_messages.append(e) _sys.stdout.write('fail\n') e_data = e.get_data() - failures.append({"name": checker.full_name(), "version" : version, - "error_description": e_data.get('error_description')}) + failures.append({ + "name": checker.full_name(), + "version" : version, + "error_description": e_data.get('error_description') + }) else: _sys.stdout.write('pass\n') successes.append((checker, version)) @@ -1046,25 +1049,26 @@ def send_to_server(successes_list, failures_list): successful_installs = [] failed_installs = failures_list for checker, version in successes_list: - successful_installs.append({"name": checker.full_name(), - "version": version}) - distribution_name = _platform.linux_distribution()[0] - distribution_version = _platform.linux_distribution()[1] - system = _platform.system() - system_version = _platform.version() - machine = _platform.machine() - system_platform = _platform.platform() - python_version = _platform.python_version() - - user_system_info = {"distribution_name": distribution_name, - "distribution_version" : distribution_version, - "system" : system, "system_version" : system_version, - "machine" : machine, "system_platform" : system_platform, - "python_version" : python_version } - headers = {"Content-Type": "application/json"} - data = {"successful_installs" : successful_installs, - "failed_installs" : failed_installs, "user_system_info":user_system_info, - "unique_user_id" : unique_id} + successful_installs.append({ + "name": checker.full_name(), + "version": version + }) + user_system_info = { + "distribution_name" : _platform.linux_distribution()[0], + "distribution_version" : _platform.linux_distribution()[1], + "system" : _platform.system(), + "system_version" : _platform.version(), + "machine" : _platform.machine(), + "system_platform" : _platform.platform(), + "python_version" : _platform.python_version() + } + headers = {"Content-Type" : "application/json"} + data = { + "successful_installs" : successful_installs, + "failed_installs" : failed_installs, + "user_system_info" : user_system_info, + "unique_user_id" : unique_id + } def senddata(): final_data = json.dumps(data) @@ -1086,26 +1090,20 @@ def senddata(): except: print("\nConnection could not be established with server!") conn.close() - def handler(signum, frame): # captures ctrl+z - senddata() - sys.exit(0) - signal.signal(signal.SIGTSTP, handler) + + global input try: - global input - try: - input = raw_input - except NameError: - pass - choice = input("\nPlease share your email id and workshop_id with us " \ - "to improve our scripts.\nAre you in ? (y/n) :") - if choice == 'y' or choice == 'Y': - email = input("Please Enter your email id: ") - data['user_system_info']['email_id'] = email - workshop_id = input("Please Enter the workshop id: ") - data['user_system_info']['workshop_id'] = workshop_id - senddata() - except KeyboardInterrupt: #for catching ctrl+c - senddata() + input = raw_input # making it compatible for Python 3.x and 2.x + except NameError: + pass + choice = input("\nPlease share your email id and workshop_id with us " \ + "to improve our scripts.\nAre you in ? (y/n) : ") + if choice == 'y' or choice == 'Y': + email = input("Please Enter your email id: ") + data['user_system_info']['email_id'] = email + workshop_id = input("Please Enter the workshop id: ") + data['user_system_info']['workshop_id'] = workshop_id + senddata() if __name__ == '__main__': import optparse as _optparse @@ -1136,4 +1134,4 @@ def handler(signum, frame): # captures ctrl+z print() print_system_info() print_suggestions(instructor_fallback=True) - _sys.exit(1) + _sys.exit(1) \ No newline at end of file From 87843dd71c4169e8754793853e054c7cfb39ee9a Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Sun, 26 Jun 2016 05:20:20 +0530 Subject: [PATCH 14/33] Updated HOST --- swc-installation-test-2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 1a1832c..7111dc1 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -79,8 +79,8 @@ def import_module(name): __version__ = '0.1' -HOST = "127.0.0.1:5000" -# HOST = "installation.software-carpentry.org" +# HOST = "127.0.0.1:5000" +HOST = "installation.software-carpentry.org" # Comment out any entries you don't need CHECKS = [ From a533054e9bab849b4f94ce8b19294456e2f58d67 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Sun, 26 Jun 2016 18:50:50 +0530 Subject: [PATCH 15/33] Added command line argument -H for changing the server to which data will be sent. --- swc-installation-test-2.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 7111dc1..2a6e996 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -1115,9 +1115,15 @@ def senddata(): '-v', '--verbose', action='store_true', help=('print additional information to help troubleshoot ' 'installation issues')) + parser.add_option( + '-H', '--host', action='store', type="string", + help=('Select the server to which the data will be sent'), dest="host_name") options,args = parser.parse_args() try: passed, successes_list, failures_list = check(args) + if options.host_name: + global HOST + HOST = options.host_name send_to_server(successes_list, failures_list) # Push data to server except InvalidCheck as e: print("I don't know how to check for {0!r}".format(e.check)) From bb259dcb0e868692aa1ab4a0312b29aaa5c103f8 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Sun, 26 Jun 2016 18:56:29 +0530 Subject: [PATCH 16/33] Removed global declaration of HOST variable in '__main__' --- swc-installation-test-2.py | 1 - 1 file changed, 1 deletion(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 2a6e996..5dba770 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -1122,7 +1122,6 @@ def senddata(): try: passed, successes_list, failures_list = check(args) if options.host_name: - global HOST HOST = options.host_name send_to_server(successes_list, failures_list) # Push data to server except InvalidCheck as e: From 009bd8a973d245e163f279798ad4fca1d602577f Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Sun, 26 Jun 2016 19:06:17 +0530 Subject: [PATCH 17/33] Added command line argument option -n for turning off sending data to server --- swc-installation-test-2.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 5dba770..661c54e 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -1117,13 +1117,20 @@ def senddata(): 'installation issues')) parser.add_option( '-H', '--host', action='store', type="string", - help=('Select the server to which the data will be sent'), dest="host_name") + help=('Change the server to which the data will be sent'), dest="host_name") + parser.add_option( + '-n', '--no_reporting', action='store_true', + help=('Turn off sending the data to server')) options,args = parser.parse_args() try: passed, successes_list, failures_list = check(args) + """Check whether host name is specified as a command line argument""" if options.host_name: HOST = options.host_name - send_to_server(successes_list, failures_list) # Push data to server + """Check whether sending data to server is turned off using + command line argument""" + if options.no_reporting is None: + send_to_server(successes_list, failures_list) # Push data to server except InvalidCheck as e: print("I don't know how to check for {0!r}".format(e.check)) print('I do know how to check for:') From 050fff396557825985776401025422020cb2562e Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Wed, 29 Jun 2016 23:17:56 +0530 Subject: [PATCH 18/33] Changed the filename from 'key.txt' to '.swc_submission_id' to keep it hidden. --- .swc_submission_id | 1 + swc-installation-test-2.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 .swc_submission_id diff --git a/.swc_submission_id b/.swc_submission_id new file mode 100644 index 0000000..902713f --- /dev/null +++ b/.swc_submission_id @@ -0,0 +1 @@ +2016-06-29[key:]f8f24632-38b6-4ec0-bd66-ee37d87b160d \ No newline at end of file diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 661c54e..829c881 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -1037,7 +1037,7 @@ def send_to_server(successes_list, failures_list): endpoint = "/installation_data/" try: - with open('key.txt', 'r') as f: + with open('.swc_submission_id', 'r') as f: first_line = f.readline() unique_id = first_line.split("[key:]")[1] date = first_line.split("[key:]")[0] @@ -1083,7 +1083,7 @@ def senddata(): print("\nSuccessfully Pushed to Server!") response = json.loads(response_string.decode('utf-8')) unique_id = response.get("key") - file = open('key.txt', 'w+') + file = open('.swc_submission_id', 'w+') file.write(str(datetime.date.today()) + "[key:]" + unique_id) else: print("\nSomething bad happened at Server!") From c941261e80050abed020f5ab5fb9c97b41db37b5 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Wed, 29 Jun 2016 23:19:18 +0530 Subject: [PATCH 19/33] Added '.swc_submission_id' to gitignore --- .gitignore | 2 +- .swc_submission_id | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 .swc_submission_id diff --git a/.gitignore b/.gitignore index d0e6d8b..1c5b9d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -key.txt \ No newline at end of file +.swc_submission_id \ No newline at end of file diff --git a/.swc_submission_id b/.swc_submission_id deleted file mode 100644 index 902713f..0000000 --- a/.swc_submission_id +++ /dev/null @@ -1 +0,0 @@ -2016-06-29[key:]f8f24632-38b6-4ec0-bd66-ee37d87b160d \ No newline at end of file From f6294e3804f02476a7e32baa719f3cf58373b82d Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Tue, 5 Jul 2016 16:37:56 +0530 Subject: [PATCH 20/33] Separated 'sending to API' code --- api.py | 81 +++++++++++++++++++++++++++++++++++ api.pyc | Bin 0 -> 3067 bytes swc-installation-test-2.py | 84 +------------------------------------ 3 files changed, 83 insertions(+), 82 deletions(-) create mode 100644 api.py create mode 100644 api.pyc diff --git a/api.py b/api.py new file mode 100644 index 0000000..5831025 --- /dev/null +++ b/api.py @@ -0,0 +1,81 @@ +import json, signal, sys, datetime, platform as _platform +try: + import httplib as http_client +except ImportError: + import http.client as http_client + +def submit(successes_list, failures_list, HOST): + """ + This function sends the details of failures and successes to server. + + """ + endpoint = "/installation_data/" + + try: + with open('.swc_submission_id', 'r') as f: + first_line = f.readline() + unique_id = first_line.split("[key:]")[1] + date = first_line.split("[key:]")[0] + if date != str(datetime.date.today()): + unique_id = None + except: + unique_id = None + + successful_installs = [] + failed_installs = failures_list + for checker, version in successes_list: + successful_installs.append({ + "name": checker.full_name(), + "version": version + }) + user_system_info = { + "distribution_name" : _platform.linux_distribution()[0], + "distribution_version" : _platform.linux_distribution()[1], + "system" : _platform.system(), + "system_version" : _platform.version(), + "machine" : _platform.machine(), + "system_platform" : _platform.platform(), + "python_version" : _platform.python_version() + } + headers = {"Content-Type" : "application/json"} + data = { + "successful_installs" : successful_installs, + "failed_installs" : failed_installs, + "user_system_info" : user_system_info, + "unique_user_id" : unique_id + } + + def senddata(): + final_data = json.dumps(data) + conn = http_client.HTTPConnection(HOST) + print("\nPushing the data to server....\n") + try: + conn.request("POST", endpoint, final_data, headers=headers) + response = conn.getresponse() + response_string = response.read() + # print(response_string) + if response.status == 200: + print("\nSuccessfully Pushed to Server!") + response = json.loads(response_string.decode('utf-8')) + unique_id = response.get("key") + file = open('.swc_submission_id', 'w+') + file.write(str(datetime.date.today()) + "[key:]" + unique_id) + else: + print("\nSomething bad happened at Server!") + except: + print("\nConnection could not be established with server!") + conn.close() + + global input + try: + input = raw_input # making it compatible for Python 3.x and 2.x + except NameError: + pass + choice = input("\nPlease share your email id and workshop_id with us " \ + "to improve our scripts.\nAre you in ? (y/n) : ") + if choice == 'y' or choice == 'Y': + email = input("Please Enter your email id: ") + data['user_system_info']['email_id'] = email + workshop_id = input("Please Enter the workshop id: ") + data['user_system_info']['workshop_id'] = workshop_id + senddata() \ No newline at end of file diff --git a/api.pyc b/api.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f0763207bd24106539c01efc75f295c50b55d33f GIT binary patch literal 3067 zcmb_dOLH4V5boX8!;&RG^CST_Tp}K};eacoQamc82p1F9u5vJ>RO_9Qweo6L*_n-_ zLOO*a$%zXWil4xL;GF-$k>U(r_e##AiW7LftDc#j?w;EA$9)SLx!k`tno_Q#G2@$a-Xv&(aMT7{RtvN}X_9Kt zHk>&3f2IAnPPR#dMOj8fs!7|=ClIw-EGJr`(JBXR8MMp6k_?v0!LkgN%fX5aR%m;= zNHLPIN@|U^pL!G{J9Sd)2xo!R8T=siXYo@dbq*R1JtlgLuS<_T>QzXcryp_J7LA)^ zS1DXWSy!oI*QKn#psEhn(XNrYzzLkTY0@Tjk&az5zdJ0y#&Z6b!#bBlXNe|D^aOF8 z#W63_4PJR&R+ee9e7f=m-9QZ{k^l#l*zLT@NZ7@v>Emy&9~-|{q>+uY)Hga+#dcYWRM8tjE{yA2;402v6c2X&_C7z39~QpqTRzofLhu2oL*dODLiRnfrmGTjl7O^maRKoOj3g_%`np z21Pq6feL)RfW^(t&89%-&R4s80-e4N6{F`Fb{YnMbN93~$=GLGTCs&)LGu;ETwd7T z#x+nI5pel0=rv$dI(hd6_?oxGd2MFp(HL}=qg2IkWRP*9zO|!nl*E9bfamt!-ks+TBoDa; zoQxIqBW=;pBVbpH#T+@Z(kwQ#g%RUP7Ahl?N=F&^fU|*(vLVBnMC&AvZMlS|vbsGA9T6%(<9r!+^j#q zBJ8M#uIjKLquX5kng3ACf!Ib_oZ5iRb?}n;2%oJ!inTS$^--7~;WrzgBxVatwSm+W zqm382Y{MddTj40)1S{}SnJ$^%-e;L>PtG!)s^d8qotD#bS-v21SKS6?8;%K~)x4AF z&}iTE!(990tjK*m1TXk8U;>go$?{{<&qkm~Um#Ej-Nr)%_(1!tZ=yUNS+m*vthC_A zssD-J8E>U;``3LT*0FrQF_+oLpUebrvnF3ty%~ISW3iIz;3_7|12V1y&XP1<)Ys9m&dVtIt_a@aB|dl5&*G@e zloTLfBndhN%i=6}hqt`TAGxId8*HV?`3{!Q%pS~AwdQ)x8UVYF=MrAeX}UG12C3n+ zon@@9;%U#G6}JtIx;#zq!Z~PTr2@ELfQ==*t4>GG$+vY$EAbJ!To?q`TnUA1e4=gE z;L0(9CGlavSDOIr%i$=?tyJff;WlRsC#e&%3vNQcOc;d!t+8(mGgTz|W3IE|YTm$! JS8&R8_a7TC$t(Z> literal 0 HcmV?d00001 diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 829c881..fc03b69 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -1023,90 +1023,10 @@ def print_suggestions(instructor_fallback=True): print('For help, email the *entire* output of this script to') print('your instructor.') -def send_to_server(successes_list, failures_list): - """ - This function sends the details of failures and successes to server. - - """ - import json, signal, sys, datetime - try: - import httplib as http_client - except ImportError: - import http.client as http_client - - endpoint = "/installation_data/" - - try: - with open('.swc_submission_id', 'r') as f: - first_line = f.readline() - unique_id = first_line.split("[key:]")[1] - date = first_line.split("[key:]")[0] - if date != str(datetime.date.today()): - unique_id = None - except: - unique_id = None - - successful_installs = [] - failed_installs = failures_list - for checker, version in successes_list: - successful_installs.append({ - "name": checker.full_name(), - "version": version - }) - user_system_info = { - "distribution_name" : _platform.linux_distribution()[0], - "distribution_version" : _platform.linux_distribution()[1], - "system" : _platform.system(), - "system_version" : _platform.version(), - "machine" : _platform.machine(), - "system_platform" : _platform.platform(), - "python_version" : _platform.python_version() - } - headers = {"Content-Type" : "application/json"} - data = { - "successful_installs" : successful_installs, - "failed_installs" : failed_installs, - "user_system_info" : user_system_info, - "unique_user_id" : unique_id - } - - def senddata(): - final_data = json.dumps(data) - conn = http_client.HTTPConnection(HOST) - print("\nPushing the data to server....\n") - try: - conn.request("POST", endpoint, final_data, headers=headers) - response = conn.getresponse() - response_string = response.read() - # print(response_string) - if response.status == 200: - print("\nSuccessfully Pushed to Server!") - response = json.loads(response_string.decode('utf-8')) - unique_id = response.get("key") - file = open('.swc_submission_id', 'w+') - file.write(str(datetime.date.today()) + "[key:]" + unique_id) - else: - print("\nSomething bad happened at Server!") - except: - print("\nConnection could not be established with server!") - conn.close() - - global input - try: - input = raw_input # making it compatible for Python 3.x and 2.x - except NameError: - pass - choice = input("\nPlease share your email id and workshop_id with us " \ - "to improve our scripts.\nAre you in ? (y/n) : ") - if choice == 'y' or choice == 'Y': - email = input("Please Enter your email id: ") - data['user_system_info']['email_id'] = email - workshop_id = input("Please Enter the workshop id: ") - data['user_system_info']['workshop_id'] = workshop_id - senddata() if __name__ == '__main__': import optparse as _optparse + import api as API parser = _optparse.OptionParser(usage='%prog [options] [check...]') epilog = __doc__ @@ -1130,7 +1050,7 @@ def senddata(): """Check whether sending data to server is turned off using command line argument""" if options.no_reporting is None: - send_to_server(successes_list, failures_list) # Push data to server + API.submit(successes_list, failures_list, HOST) except InvalidCheck as e: print("I don't know how to check for {0!r}".format(e.check)) print('I do know how to check for:') From 5d6f6113396b1cca858ac5e1fead1ff4e2dac250 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Tue, 5 Jul 2016 16:41:24 +0530 Subject: [PATCH 21/33] Removed .pyc file and added to gitignore --- .gitignore | 3 ++- api.pyc | Bin 3067 -> 0 bytes 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 api.pyc diff --git a/.gitignore b/.gitignore index 1c5b9d2..fa8607c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.swc_submission_id \ No newline at end of file +.swc_submission_id +*.pyc \ No newline at end of file diff --git a/api.pyc b/api.pyc deleted file mode 100644 index f0763207bd24106539c01efc75f295c50b55d33f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3067 zcmb_dOLH4V5boX8!;&RG^CST_Tp}K};eacoQamc82p1F9u5vJ>RO_9Qweo6L*_n-_ zLOO*a$%zXWil4xL;GF-$k>U(r_e##AiW7LftDc#j?w;EA$9)SLx!k`tno_Q#G2@$a-Xv&(aMT7{RtvN}X_9Kt zHk>&3f2IAnPPR#dMOj8fs!7|=ClIw-EGJr`(JBXR8MMp6k_?v0!LkgN%fX5aR%m;= zNHLPIN@|U^pL!G{J9Sd)2xo!R8T=siXYo@dbq*R1JtlgLuS<_T>QzXcryp_J7LA)^ zS1DXWSy!oI*QKn#psEhn(XNrYzzLkTY0@Tjk&az5zdJ0y#&Z6b!#bBlXNe|D^aOF8 z#W63_4PJR&R+ee9e7f=m-9QZ{k^l#l*zLT@NZ7@v>Emy&9~-|{q>+uY)Hga+#dcYWRM8tjE{yA2;402v6c2X&_C7z39~QpqTRzofLhu2oL*dODLiRnfrmGTjl7O^maRKoOj3g_%`np z21Pq6feL)RfW^(t&89%-&R4s80-e4N6{F`Fb{YnMbN93~$=GLGTCs&)LGu;ETwd7T z#x+nI5pel0=rv$dI(hd6_?oxGd2MFp(HL}=qg2IkWRP*9zO|!nl*E9bfamt!-ks+TBoDa; zoQxIqBW=;pBVbpH#T+@Z(kwQ#g%RUP7Ahl?N=F&^fU|*(vLVBnMC&AvZMlS|vbsGA9T6%(<9r!+^j#q zBJ8M#uIjKLquX5kng3ACf!Ib_oZ5iRb?}n;2%oJ!inTS$^--7~;WrzgBxVatwSm+W zqm382Y{MddTj40)1S{}SnJ$^%-e;L>PtG!)s^d8qotD#bS-v21SKS6?8;%K~)x4AF z&}iTE!(990tjK*m1TXk8U;>go$?{{<&qkm~Um#Ej-Nr)%_(1!tZ=yUNS+m*vthC_A zssD-J8E>U;``3LT*0FrQF_+oLpUebrvnF3ty%~ISW3iIz;3_7|12V1y&XP1<)Ys9m&dVtIt_a@aB|dl5&*G@e zloTLfBndhN%i=6}hqt`TAGxId8*HV?`3{!Q%pS~AwdQ)x8UVYF=MrAeX}UG12C3n+ zon@@9;%U#G6}JtIx;#zq!Z~PTr2@ELfQ==*t4>GG$+vY$EAbJ!To?q`TnUA1e4=gE z;L0(9CGlavSDOIr%i$=?tyJff;WlRsC#e&%3vNQcOc;d!t+8(mGgTz|W3IE|YTm$! JS8&R8_a7TC$t(Z> From 8c0186dc17a13c3a7a14429703550e2f310e432c Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Tue, 5 Jul 2016 17:19:00 +0530 Subject: [PATCH 22/33] Separated CHECKS list and calling functions to test the requirements. swc-main.py is now the main file, which need to be run. It imports requirements_check.py and api.py for checking and pushing the data to server --- ...llation-test-2.py => requirements_check.py | 93 +------------------ swc-main.py | 92 ++++++++++++++++++ 2 files changed, 95 insertions(+), 90 deletions(-) rename swc-installation-test-2.py => requirements_check.py (92%) mode change 100755 => 100644 create mode 100644 swc-main.py diff --git a/swc-installation-test-2.py b/requirements_check.py old mode 100755 new mode 100644 similarity index 92% rename from swc-installation-test-2.py rename to requirements_check.py index fc03b69..6dc3c5b --- a/swc-installation-test-2.py +++ b/requirements_check.py @@ -80,48 +80,6 @@ def import_module(name): __version__ = '0.1' # HOST = "127.0.0.1:5000" -HOST = "installation.software-carpentry.org" - -# Comment out any entries you don't need -CHECKS = [ -# Shell - 'virtual-shell', -# Editors - 'virtual-editor', -# Browsers - 'virtual-browser', -# Version control - 'git', - 'hg', # Command line tool - #'mercurial', # Python package - 'EasyMercurial', -# Build tools and packaging - 'make', - 'virtual-pypi-installer', - 'setuptools', - #'xcode', -# Testing - 'nosetests', # Command line tool - 'nose', # Python package - 'py.test', # Command line tool - 'pytest', # Python package -# SQL - 'sqlite3', # Command line tool - 'sqlite3-python', # Python package -# Python - 'python', - 'ipython', # Command line tool - 'IPython', # Python package - 'argparse', # Useful for utility scripts - 'numpy', - 'scipy', - 'matplotlib', - 'pandas', - # 'sympy', - # 'Cython', - # 'networkx', - # 'mayavi.mlab', - ] CHECKER = {} @@ -257,8 +215,8 @@ def check(checks=None): successes = [] failures = [] failure_messages = [] - if not checks: - checks = CHECKS + # if not checks: + # checks = CHECKS for check in checks: try: checker = CHECKER[check] @@ -1021,49 +979,4 @@ def print_suggestions(instructor_fallback=True): if instructor_fallback: print('') print('For help, email the *entire* output of this script to') - print('your instructor.') - - -if __name__ == '__main__': - import optparse as _optparse - import api as API - - parser = _optparse.OptionParser(usage='%prog [options] [check...]') - epilog = __doc__ - parser.format_epilog = lambda formatter: '\n' + epilog - parser.add_option( - '-v', '--verbose', action='store_true', - help=('print additional information to help troubleshoot ' - 'installation issues')) - parser.add_option( - '-H', '--host', action='store', type="string", - help=('Change the server to which the data will be sent'), dest="host_name") - parser.add_option( - '-n', '--no_reporting', action='store_true', - help=('Turn off sending the data to server')) - options,args = parser.parse_args() - try: - passed, successes_list, failures_list = check(args) - """Check whether host name is specified as a command line argument""" - if options.host_name: - HOST = options.host_name - """Check whether sending data to server is turned off using - command line argument""" - if options.no_reporting is None: - API.submit(successes_list, failures_list, HOST) - except InvalidCheck as e: - print("I don't know how to check for {0!r}".format(e.check)) - print('I do know how to check for:') - for key,checker in sorted(CHECKER.items()): - if checker.long_name != checker.name: - print(' {0} {1}({2})'.format( - key, ' '*(20-len(key)), checker.long_name)) - else: - print(' {0}'.format(key)) - _sys.exit(1) - if not passed: - if options.verbose: - print() - print_system_info() - print_suggestions(instructor_fallback=True) - _sys.exit(1) \ No newline at end of file + print('your instructor.') \ No newline at end of file diff --git a/swc-main.py b/swc-main.py new file mode 100644 index 0000000..294e51f --- /dev/null +++ b/swc-main.py @@ -0,0 +1,92 @@ +import requirements_check +from requirements_check import InvalidCheck, CHECKER +import api as API +import optparse as _optparse +import sys as _sys + +HOST = "installation.software-carpentry.org" + +# Comment out any entries you don't need +CHECKS = [ +# Shell + 'virtual-shell', +# Editors + 'virtual-editor', +# Browsers + 'virtual-browser', +# Version control + 'git', + 'hg', # Command line tool + #'mercurial', # Python package + 'EasyMercurial', +# Build tools and packaging + 'make', + 'virtual-pypi-installer', + 'setuptools', + #'xcode', +# Testing + 'nosetests', # Command line tool + 'nose', # Python package + 'py.test', # Command line tool + 'pytest', # Python package +# SQL + 'sqlite3', # Command line tool + 'sqlite3-python', # Python package +# Python + 'python', + 'ipython', # Command line tool + 'IPython', # Python package + 'argparse', # Useful for utility scripts + 'numpy', + 'scipy', + 'matplotlib', + 'pandas', + # 'sympy', + # 'Cython', + # 'networkx', + # 'mayavi.mlab', + ] + +if __name__ == '__main__': + + parser = _optparse.OptionParser(usage='%prog [options] [check...]') + epilog = __doc__ + parser.format_epilog = lambda formatter: '\n' + epilog + parser.add_option( + '-v', '--verbose', action='store_true', + help=('print additional information to help troubleshoot ' + 'installation issues')) + parser.add_option( + '-H', '--host', action='store', type="string", + help=('Change the server to which the data will be sent'), dest="host_name") + parser.add_option( + '-n', '--no_reporting', action='store_true', + help=('Turn off sending the data to server')) + options,args = parser.parse_args() + try: + if not args: + args = CHECKS + passed, successes_list, failures_list = requirements_check.check(args) + """Check whether host name is specified as a command line argument""" + if options.host_name: + HOST = options.host_name + """Check whether sending data to server is turned off using + command line argument""" + if options.no_reporting is None: + API.submit(successes_list, failures_list, HOST) + except InvalidCheck as e: + print("I don't know how to check for {0!r}".format(e.check)) + print('I do know how to check for:') + for key,checker in sorted(CHECKER.items()): + if checker.long_name != checker.name: + print(' {0} {1}({2})'.format( + key, ' '*(20-len(key)), checker.long_name)) + else: + print(' {0}'.format(key)) + _sys.exit(1) + if not passed: + if options.verbose: + print() + requirements_check.print_system_info() + requirements_check.print_suggestions(instructor_fallback=True) + _sys.exit(1) \ No newline at end of file From d661167d433f5bda2a980809f3d43f331561c812 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Wed, 6 Jul 2016 00:06:39 +0530 Subject: [PATCH 23/33] Merged script 1 into swc-main.py. So now the script first checks for the existing python version, and if the check is passed, then only other requirements are being checked using requirements_check.py --- swc-installation-test-1.py | 56 -------------------------------------- swc-main.py | 16 +++++++++++ 2 files changed, 16 insertions(+), 56 deletions(-) delete mode 100755 swc-installation-test-1.py diff --git a/swc-installation-test-1.py b/swc-installation-test-1.py deleted file mode 100755 index be027f9..0000000 --- a/swc-installation-test-1.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python - -"""Test script to check required Python version. - -Execute this code at the command line by typing: - - python swc-installation-test-1.py - -How to get a command line: - -- On OSX run this with the Terminal application. - -- On Windows, go to the Start menu, select 'Run' and type 'cmd' -(without the quotes) to run the 'cmd.exe' Windows Command Prompt. - -- On Linux, either use your login shell directly, or run one of a - number of graphical terminals (e.g. 'xterm', 'gnome-terminal', ...). - -For some screen shots, see: - - http://software-carpentry.org/setup/terminal.html - -Run the script and follow the instructions it prints at the end. If -you see an error saying that the 'python' command was not found, than -you may not have any version of Python installed. See: - - http://www.python.org/download/releases/2.7.3/#download - -for installation instructions. - -This test is separate to avoid Python syntax errors parsing the more -elaborate `swc-installation-test-2.py`. -""" - -import sys as _sys - - -__version__ = '0.1' - - -def check(): - if _sys.version_info < (2, 6): - print('check for Python version (python):') - print('outdated version of Python: ' + _sys.version) - return False - return True - - -if __name__ == '__main__': - if check(): - print('Passed') - else: - print('Failed') - print('Install a current version of Python!') - print('http://www.python.org/download/releases/2.7.3/#download') - _sys.exit(1) diff --git a/swc-main.py b/swc-main.py index 294e51f..ee8d28a 100644 --- a/swc-main.py +++ b/swc-main.py @@ -47,8 +47,24 @@ # 'mayavi.mlab', ] +def python_version_check(): + print("Checking for python version...") + if _sys.version_info < (2, 6): + print('check for Python version (python):') + print('outdated version of Python: ' + _sys.version) + return False + return True + if __name__ == '__main__': + if python_version_check(): + print('Passed') + else: + print('Failed') + print('Install a current version of Python!') + print('http://www.python.org/download/releases/2.7.3/#download') + _sys.exit(1) + parser = _optparse.OptionParser(usage='%prog [options] [check...]') epilog = __doc__ parser.format_epilog = lambda formatter: '\n' + epilog From ffc44535f49a0f1e6a36102ac3ccba94dd7d7b2b Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Wed, 6 Jul 2016 02:19:48 +0530 Subject: [PATCH 24/33] Changed the download link to python3 instead of python2 --- swc-main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swc-main.py b/swc-main.py index ee8d28a..9b3545a 100644 --- a/swc-main.py +++ b/swc-main.py @@ -62,7 +62,7 @@ def python_version_check(): else: print('Failed') print('Install a current version of Python!') - print('http://www.python.org/download/releases/2.7.3/#download') + print('https://www.python.org/downloads/release/python-352/') _sys.exit(1) parser = _optparse.OptionParser(usage='%prog [options] [check...]') From eeba4336737895fefb70692e4c7c190d8aa659a4 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Mon, 15 Aug 2016 13:23:45 +0530 Subject: [PATCH 25/33] Updated the python download link --- requirements_check.py | 2 +- swc-main.py | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/requirements_check.py b/requirements_check.py index 6dc3c5b..27168da 100644 --- a/requirements_check.py +++ b/requirements_check.py @@ -979,4 +979,4 @@ def print_suggestions(instructor_fallback=True): if instructor_fallback: print('') print('For help, email the *entire* output of this script to') - print('your instructor.') \ No newline at end of file + print('your instructor.') diff --git a/swc-main.py b/swc-main.py index 9b3545a..8c22389 100644 --- a/swc-main.py +++ b/swc-main.py @@ -8,31 +8,31 @@ # Comment out any entries you don't need CHECKS = [ -# Shell + # Shell 'virtual-shell', -# Editors + # Editors 'virtual-editor', -# Browsers + # Browsers 'virtual-browser', -# Version control + # Version control 'git', 'hg', # Command line tool - #'mercurial', # Python package + # 'mercurial', # Python package 'EasyMercurial', -# Build tools and packaging + # Build tools and packaging 'make', 'virtual-pypi-installer', 'setuptools', - #'xcode', -# Testing + # 'xcode', + # Testing 'nosetests', # Command line tool 'nose', # Python package 'py.test', # Command line tool 'pytest', # Python package -# SQL + # SQL 'sqlite3', # Command line tool 'sqlite3-python', # Python package -# Python + # Python 'python', 'ipython', # Command line tool 'IPython', # Python package @@ -45,7 +45,8 @@ # 'Cython', # 'networkx', # 'mayavi.mlab', - ] +] + def python_version_check(): print("Checking for python version...") @@ -61,8 +62,7 @@ def python_version_check(): print('Passed') else: print('Failed') - print('Install a current version of Python!') - print('https://www.python.org/downloads/release/python-352/') + print('Install the newest version from https://www.python.org/downloads/ or ask instructors for help') _sys.exit(1) parser = _optparse.OptionParser(usage='%prog [options] [check...]') @@ -78,7 +78,7 @@ def python_version_check(): parser.add_option( '-n', '--no_reporting', action='store_true', help=('Turn off sending the data to server')) - options,args = parser.parse_args() + options, args = parser.parse_args() try: if not args: args = CHECKS @@ -93,10 +93,10 @@ def python_version_check(): except InvalidCheck as e: print("I don't know how to check for {0!r}".format(e.check)) print('I do know how to check for:') - for key,checker in sorted(CHECKER.items()): + for key, checker in sorted(CHECKER.items()): if checker.long_name != checker.name: print(' {0} {1}({2})'.format( - key, ' '*(20-len(key)), checker.long_name)) + key, ' ' * (20 - len(key)), checker.long_name)) else: print(' {0}'.format(key)) _sys.exit(1) @@ -105,4 +105,4 @@ def python_version_check(): print() requirements_check.print_system_info() requirements_check.print_suggestions(instructor_fallback=True) - _sys.exit(1) \ No newline at end of file + _sys.exit(1) From c98d912457d921d038240d028b79ba3a7379b4eb Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Mon, 15 Aug 2016 13:35:31 +0530 Subject: [PATCH 26/33] Added docstring for swc-main.py --- swc-main.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/swc-main.py b/swc-main.py index 8c22389..d3fb662 100644 --- a/swc-main.py +++ b/swc-main.py @@ -1,3 +1,39 @@ +"""Test script to check for required functionality. + +Execute this code at the command line by typing: + + python swc-main.py + +Run the script and follow the instructions it prints at the end. + +This script requires at least Python 2.6. It will first check for the +existing version of python installed on your system, and will proceed further +only if you have at least Python 2.6. + +By default, this script will test for all the dependencies your +instructor thinks you need. If you want to test for a different set +of packages, you can list them on the command line. For example: + + python swc-main.py git virtual-editor + + This is useful if the original test told you to install a more recent + version of a particular dependency, and you just want to re-test that + dependency. + """ +# Some details about the implementation: + +# CHECKS list stores a list of the dependencies which are to be checked in +# the current workshop. + +# In the "__name__ == '__main__'" block, we launch all the checks with +# check() function of requirements_check.py, which prints information about the tests as they run +# and details about the failures after the tests complete. In case of +# failure, the functions print_system_info() and print_suggestions() +# are called after this, where the former prints information about the +# user's system for debugging purposes while the latter prints some +# suggestions to follow. + + import requirements_check from requirements_check import InvalidCheck, CHECKER import api as API From b7bafc0e288e5cefc20a65f54c0a057ef44671d6 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Mon, 15 Aug 2016 13:37:42 +0530 Subject: [PATCH 27/33] Modified the docstring of requirements_check.py --- requirements_check.py | 45 +++++++------------------------------------ 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/requirements_check.py b/requirements_check.py index 27168da..f054d58 100644 --- a/requirements_check.py +++ b/requirements_check.py @@ -1,45 +1,14 @@ #!/usr/bin/env python -"""Test script to check for required functionality. +""" +Some details about the implementation: -Execute this code at the command line by typing: - - python swc-installation-test-2.py - -Run the script and follow the instructions it prints at the end. - -This script requires at least Python 2.6. You can check the version -of Python that you have installed with 'swc-installation-test-1.py'. - -By default, this script will test for all the dependencies your -instructor thinks you need. If you want to test for a different set -of packages, you can list them on the command line. For example: - - python swc-installation-test-2.py git virtual-editor - - This is useful if the original test told you to install a more recent - version of a particular dependency, and you just want to re-test that - dependency. - """ - - # Some details about the implementation: - - # The dependencies are divided into a hierarchy of classes rooted on - # Dependency class. You can refer to the code to see which package - # comes under which type of dependency. - - # The CHECKER dictionary stores information about all the dependencies - # and CHECKS stores list of the dependencies which are to be checked in - # the current workshop. - - # In the "__name__ == '__main__'" block, we launch all the checks with - # check() function, which prints information about the tests as they run - # and details about the failures after the tests complete. In case of - # failure, the functions print_system_info() and print_suggestions() - # are called after this, where the former prints information about the -# user's system for debugging purposes while the latter prints some -# suggestions to follow. +The dependencies are divided into a hierarchy of classes rooted on +Dependency class. You can refer to the code to see which package +comes under which type of dependency. +The CHECKER dictionary stores information about all the dependencies +""" from __future__ import print_function # for Python 2.6 compatibility From 497d8642474734c9a7d7565ceaa02e36ff2710f7 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Mon, 15 Aug 2016 14:06:42 +0530 Subject: [PATCH 28/33] Changed phrase for taking input of workshop id from user. If the user doesn't provide the workshop id, it is set to 'No workshop name provided' --- api.py | 78 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/api.py b/api.py index 5831025..44dd76a 100644 --- a/api.py +++ b/api.py @@ -1,14 +1,19 @@ -import json, signal, sys, datetime, platform as _platform -try: +import json +import sys +import datetime +import platform as _platform + +try: import httplib as http_client except ImportError: import http.client as http_client + def submit(successes_list, failures_list, HOST): """ This function sends the details of failures and successes to server. - """ + endpoint = "/installation_data/" try: @@ -24,36 +29,39 @@ def submit(successes_list, failures_list, HOST): successful_installs = [] failed_installs = failures_list for checker, version in successes_list: - successful_installs.append({ - "name": checker.full_name(), - "version": version - }) + successful_installs.append( + { + "name": checker.full_name(), + "version": version + } + ) + user_system_info = { - "distribution_name" : _platform.linux_distribution()[0], - "distribution_version" : _platform.linux_distribution()[1], - "system" : _platform.system(), - "system_version" : _platform.version(), - "machine" : _platform.machine(), - "system_platform" : _platform.platform(), - "python_version" : _platform.python_version() - } - headers = {"Content-Type" : "application/json"} + "distribution_name": _platform.linux_distribution()[0], + "distribution_version": _platform.linux_distribution()[1], + "system": _platform.system(), + "system_version": _platform.version(), + "machine": _platform.machine(), + "system_platform": _platform.platform(), + "python_version": _platform.python_version() + } + + headers = {"Content-Type": "application/json"} data = { - "successful_installs" : successful_installs, - "failed_installs" : failed_installs, - "user_system_info" : user_system_info, - "unique_user_id" : unique_id - } - + "successful_installs": successful_installs, + "failed_installs": failed_installs, + "user_system_info": user_system_info, + "unique_user_id": unique_id + } + def senddata(): - final_data = json.dumps(data) + final_data = json.dumps(data) conn = http_client.HTTPConnection(HOST) print("\nPushing the data to server....\n") try: - conn.request("POST", endpoint, final_data, headers=headers) + conn.request("POST", endpoint, final_data, headers=headers) response = conn.getresponse() response_string = response.read() - # print(response_string) if response.status == 200: print("\nSuccessfully Pushed to Server!") response = json.loads(response_string.decode('utf-8')) @@ -61,21 +69,27 @@ def senddata(): file = open('.swc_submission_id', 'w+') file.write(str(datetime.date.today()) + "[key:]" + unique_id) else: - print("\nSomething bad happened at Server!") + print("\nSomething bad happened at Server!") except: print("\nConnection could not be established with server!") conn.close() global input try: - input = raw_input # making it compatible for Python 3.x and 2.x + input = raw_input # making it compatible for Python 3.x and 2.x except NameError: pass - choice = input("\nPlease share your email id and workshop_id with us " \ - "to improve our scripts.\nAre you in ? (y/n) : ") + choice = input("\nTo improve our lessons, we gather anonymous data about failed package installations." + " Can we send anonymous list of your packages? (y/N): ") if choice == 'y' or choice == 'Y': - email = input("Please Enter your email id: ") + workshop_id = input("Please enter your workshop name (similar to '2016-08-13-place', ask your instructor for details) (none by default): ") + if not workshop_id: + workshop_id = "No workshop name provided" + email = input("What is your email address (none by default): ") + if not email: + email = None data['user_system_info']['email_id'] = email - workshop_id = input("Please Enter the workshop id: ") data['user_system_info']['workshop_id'] = workshop_id - senddata() \ No newline at end of file + senddata() + else: + sys.exit(0) From 02618d19c09d3dc4f61aa73b9a62bbf6c56ef8d6 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Mon, 15 Aug 2016 14:23:18 +0530 Subject: [PATCH 29/33] Change the default workshop id to None, and handled it at server side --- api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.py b/api.py index 44dd76a..28b352f 100644 --- a/api.py +++ b/api.py @@ -84,7 +84,7 @@ def senddata(): if choice == 'y' or choice == 'Y': workshop_id = input("Please enter your workshop name (similar to '2016-08-13-place', ask your instructor for details) (none by default): ") if not workshop_id: - workshop_id = "No workshop name provided" + workshop_id = None email = input("What is your email address (none by default): ") if not email: email = None From b59c22df6a40eadbf765cf39bb346126f7976291 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Mon, 15 Aug 2016 14:28:45 +0530 Subject: [PATCH 30/33] Add docstring for api.py --- api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api.py b/api.py index 28b352f..3428542 100644 --- a/api.py +++ b/api.py @@ -1,3 +1,8 @@ +""" +This file sends the data collected by the script 'swc-main.py' +to server. +""" + import json import sys import datetime From b0a2f0abc1efe10b01193f88b545d55e75019150 Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Mon, 15 Aug 2016 15:01:23 +0530 Subject: [PATCH 31/33] Updated readme --- README.md | 26 ++++++++++++++------------ api.py | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 35ff0d2..1ac2984 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ For learners ============ -This directory contains scripts for testing your machine to make sure +This directory contains script for testing your machine to make sure you have the software you'll need for your workshop installed. See the comments at the head of each script for more details, but you'll basically want to see something like: - $ python swc-installation-test-1.py + $ python swc-main.py + Checking for python version... Passed - $ python swc-installation-test-2.py - check virtual-shell... pass - … + check command line shell (virtual-shell)... pass + ... Successes: virtual-shell Bourne Again Shell (bash) 4.2.37 @@ -18,7 +18,9 @@ basically want to see something like: If you see something like: - $ python swc-installation-test-2.py + $ python swc-main.py + Checking for python version... + Passed check virtual-shell... fail … check for command line shell (virtual-shell) failed: @@ -36,7 +38,7 @@ follow the suggestions to try and install any missing software. For additional troubleshooting information, you can use the `--verbose` option: - $ python swc-installation-test-2.py --verbose + $ python swc-main.py --verbose check virtual-shell... fail … ================== @@ -48,17 +50,17 @@ option: For instructors =============== -`swc-installation-test-1.py` is pretty simple, and just checks that -the students have a recent enough version of Python installed that -they'll be able to parse `swc-installation-test-2.py`. The latter -checks for a list of dependencies and prints error messages if a +`swc-main.py` first checks that the students have a recent enough +version of Python installed that they'll be able to parse +`swc-main.py` completely. If python version is found to be at least 2.6, +then it checks for a list of dependencies and prints error messages if a package is not installed, or if the installed version is not current enough. By default, the script checks for pretty much anything that has ever been used at a Software Carpentry workshop, which is probably not what you want for your particular workshop. Before your workshop, you should go through -`swc-installation-test-2.py` and comment any dependencies you don't +`swc-main.py` and comment any dependencies you don't need out of the `CHECKS` list. You might also want to skim through the minimum version numbers listed where particular dependencies are defined (e.g. `('git', 'Git', (1, 7, 0), None)`). For the most part, diff --git a/api.py b/api.py index 3428542..f4da448 100644 --- a/api.py +++ b/api.py @@ -97,4 +97,4 @@ def senddata(): data['user_system_info']['workshop_id'] = workshop_id senddata() else: - sys.exit(0) + return From 84eece902ad84a4d3767ddc4bc7f1e00065503ea Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Thu, 18 Aug 2016 01:42:14 +0530 Subject: [PATCH 32/33] Added travis.yml --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e1763eb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: python +python: + - "2.6" + - "2.7" + - "3.2" + - "3.3" + - "3.4" + - "3.5" + +script: + - python swc-main.py -n \ No newline at end of file From f0202bb5d742e8abf1fe27503ae989692663941b Mon Sep 17 00:00:00 2001 From: Prerit Garg Date: Thu, 18 Aug 2016 01:55:28 +0530 Subject: [PATCH 33/33] changed exit code to 0 --- .travis.yml | 2 +- swc-main.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e1763eb..c39bb13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,4 @@ python: - "3.5" script: - - python swc-main.py -n \ No newline at end of file + - python swc-main.py -n diff --git a/swc-main.py b/swc-main.py index d3fb662..24fae0f 100644 --- a/swc-main.py +++ b/swc-main.py @@ -99,7 +99,7 @@ def python_version_check(): else: print('Failed') print('Install the newest version from https://www.python.org/downloads/ or ask instructors for help') - _sys.exit(1) + _sys.exit(0) parser = _optparse.OptionParser(usage='%prog [options] [check...]') epilog = __doc__ @@ -135,10 +135,10 @@ def python_version_check(): key, ' ' * (20 - len(key)), checker.long_name)) else: print(' {0}'.format(key)) - _sys.exit(1) + _sys.exit(0) if not passed: if options.verbose: print() requirements_check.print_system_info() requirements_check.print_suggestions(instructor_fallback=True) - _sys.exit(1) + _sys.exit(0)