Last active
April 25, 2019 07:51
-
-
Save foxmask/9668068 to your computer and use it in GitHub Desktop.
http://sametmax.com/exercice-python-round-3/ - pas sûr mais just 4 fun :)
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
# -*- coding: utf-8 -*- | |
import os | |
import argparse | |
""" | |
to test it : python go.py <filename> | |
check it with python go.py -h ;) | |
""" | |
def do_action(args): | |
""" handles the replacing stuff in a binary file """ | |
if os.path.isfile(args.file) is False: | |
# dude miss something | |
print("this file does not exist") | |
else: | |
# what we want to drop | |
old_str = b'_NET_ACTIVE_WINDOW' | |
# what we want to put instead | |
new_str = b' ' | |
# load the file in memory | |
buf = open(args.file, 'rb').read().replace(old_str, new_str) | |
# write it | |
# yes I know if nothing is found I do write for nothing | |
open(args.file, 'wb').write(buf) | |
def main(): | |
"""Sam et Max : Exercice Episode 3 """ | |
# main.__doc__ does the trick to get the docstring in the help ;) | |
parser = argparse.ArgumentParser(prog="go", | |
usage='%(prog)s [options]', | |
description=main.__doc__, | |
conflict_handler='resolve', | |
add_help=True) | |
parser.add_argument('file', help='the path of the file') | |
args = parser.parse_args() | |
do_action(args) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment