Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brunneis committed May 27, 2021
1 parent c37e553 commit 39ef4b1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 36 deletions.
6 changes: 0 additions & 6 deletions package_name/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions package_name/package_name.py

This file was deleted.

21 changes: 0 additions & 21 deletions rename.sh

This file was deleted.

6 changes: 6 additions & 0 deletions safemode/__init__.py
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'
45 changes: 45 additions & 0 deletions safemode/safemode.py
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...')
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 39ef4b1

Please sign in to comment.