Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get-shit-done.py: flake8 style changes #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions get-shit-done.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import os
from os import path


def exit_error(error):
print(error, file=sys.stderr)
exit(1)


ini_local = path.expanduser(path.join("~", ".config/get-shit-done.ini"))
ini_global = './sites.ini'

Expand All @@ -26,6 +28,7 @@ def exit_error(error):
message = '"Please contribute DNS cache flush command on GitHub."'
restart_network_command = ['echo', message]


def ini_to_array(ini_file):
# this enables the ini file to be written like
# sites = google.com, facebook.com, quora.com ....
Expand All @@ -39,7 +42,8 @@ def ini_to_array(ini_file):
sites.append(item)
return sites
else:
return []
return []


hosts_file = '/etc/hosts'

Expand All @@ -50,9 +54,11 @@ def ini_to_array(ini_file):
end_token = '## end-gsd'
site_list = ini_to_array(ini_global) + ini_to_array(ini_local)


def rehash():
subprocess.check_call(restart_network_command)


def work():
hFile = open(hosts_file, 'a+')
contents = hFile.read()
Expand All @@ -71,6 +77,7 @@ def work():

rehash()


def play():
hosts_file_handle = open(hosts_file, "r+")
lines = hosts_file_handle.readlines()
Expand All @@ -90,6 +97,7 @@ def play():

rehash()


def main():
if getpass.getuser() != 'root' and 'win32' not in sys.platform:
exit_error('Please run script as root.')
Expand All @@ -98,7 +106,8 @@ def main():
try:
{"work": work, "play": play}[sys.argv[1]]()
except KeyError:
exit_error('usage: ' + sys.argv[0] + ' [work|play]')
exit_error('usage: ' + sys.argv[0] + ' [work|play]')


if __name__ == "__main__":
main()