generated from labteral/python-package
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
58 additions
and
36 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from .safemode import * | ||
|
||
__version__ = '1.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import time | ||
from threading import Thread | ||
import sys, tty, termios | ||
import os | ||
|
||
if 'SAFEMODE_GRACE_PERIOD' in os.environ: | ||
SAFEMODE_GRACE_PERIOD = os.environ['SAFEMODE_GRACE_PERIOD'] | ||
else: | ||
SAFEMODE_GRACE_PERIOD = 5 | ||
|
||
|
||
def configure_tty(): | ||
old_settings = termios.tcgetattr(sys.stdin.fileno()) | ||
tty.setraw(sys.stdin.fileno()) | ||
return old_settings | ||
|
||
|
||
def restore_tty(old_settings): | ||
termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, old_settings) | ||
|
||
|
||
def capture_key(): | ||
global key_pressed | ||
key_pressed = sys.stdin.read(1) | ||
|
||
|
||
def launch_shell(): | ||
os.execv('/bin/sh', (' ', )) | ||
|
||
|
||
print('[safemode] To start a shell, ' | ||
f'press any key before {SAFEMODE_GRACE_PERIOD} seconds...') | ||
old_settings = configure_tty() | ||
key_pressed = False | ||
thread = Thread(target=capture_key, daemon=True).start() | ||
for _ in range(SAFEMODE_GRACE_PERIOD): | ||
if key_pressed: | ||
restore_tty(old_settings) | ||
launch_shell() | ||
time.sleep(1) | ||
restore_tty(old_settings) | ||
print(f'[safemode] Starting up normally...') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,15 @@ | |
|
||
from setuptools import setup | ||
from setuptools import find_packages | ||
import package_name | ||
import safemode | ||
|
||
setup( | ||
name='package_name', | ||
version=package_name.__version__, | ||
description='description_value', | ||
url='url_value', | ||
author='author_value', | ||
author_email='email_value', | ||
name='safemode', | ||
version=safemode.__version__, | ||
description='Open a terminal if any key is pressed during start up', | ||
url='https://github.com/labteral/safemode', | ||
author='Rodrigo Martínez Castaño', | ||
author_email='[email protected]', | ||
license='GNU General Public License v3 (GPLv3)', | ||
packages=find_packages(), | ||
zip_safe=False, | ||
|