├── src ├── __init__.py ├── errors.py ├── filetools.py ├── help.py ├── initialize.py ├── configreader.py └── LICENSE ├── tests ├── __init__.py ├── test_directory │ ├── hs_music │ │ ├── fake_music1.mp3 │ │ ├── fake_music2.mp3 │ │ └── more music │ │ │ └── fake_music3.mp3 │ └── hs_wallpaper │ │ ├── fake_wallpaper1.jpg │ │ ├── fake_wallpaper2.jpg │ │ ├── not a wallpaper.txt │ │ └── more wallpapers │ │ └── fake_wallpaper3.jpg ├── test_config.ini ├── configgenertor.py └── test_configreader.py ├── docs ├── footer.txt ├── header.txt ├── hs-schedule.txt ├── tip1.txt ├── hs-config.txt ├── hs-browse.txt ├── hs-wallpaper.txt ├── hs-work.txt ├── hs-start.txt ├── hs-music.txt ├── hs-desktop.txt ├── hs-manage.txt └── hs-backup.txt ├── .gitattributes ├── .gitignore ├── delete_playlist.py ├── add_to_path.py ├── hs-watch.py ├── README.rst ├── hs-browse.py ├── hs-start.py ├── hs-work.py ├── hs-wallpaper.py ├── hs-music.py ├── hs-help.py ├── hs-desktop.py ├── hs-manage.py ├── hs-backup.py ├── hs-config.py ├── hs-schedule.py └── LICENSE /src/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/test_directory/hs_music/fake_music1.mp3: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/test_directory/hs_music/fake_music2.mp3: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/test_directory/hs_wallpaper/fake_wallpaper1.jpg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/test_directory/hs_wallpaper/fake_wallpaper2.jpg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/test_directory/hs_wallpaper/not a wallpaper.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/test_directory/hs_music/more music/fake_music3.mp3: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/test_directory/hs_wallpaper/more wallpapers/fake_wallpaper3.jpg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/footer.txt: -------------------------------------------------------------------------------- 1 | 2 | *** hacker-scripts Copyright (C) 2016 Areeb Beigh *** 3 | 4 | -------------------------------------------------------------------------------- /docs/header.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------ 2 | 3 | * Python hacker-scripts by Areeb 4 | * github.com/areebbeigh/hacker-scripts 5 | 6 | ------------------------------------------ 7 | -------------------------------------------------------------------------------- /docs/hs-schedule.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-schedule 5 | 6 | Schedules other hacker-scripts commands to be executed some time in the future. 7 | It also allows you to delete already scheduled tasks. 8 | 9 | This script uses the windows SCHTASKS command to create scheduled tasks. 10 | 11 | USAGE 12 | ----- 13 | 14 | Check hs-schedule -h 15 | -------------------------------------------------------------------------------- /docs/tip1.txt: -------------------------------------------------------------------------------- 1 | 2 | ---------------------------------------------------------------------------- 3 | -TIP- 4 | If you're using a command that requires some arguments (such as 5 | hs-schedule or hs-manage) in Command Prompt and it does not parse 6 | the arguments then use Windows PowerShell instead. 7 | 8 | ---------------------------------------------------------------------------- -------------------------------------------------------------------------------- /docs/hs-config.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-config 5 | 6 | Creates a new configuration file named 'config.ini' in the hacker-scripts 7 | main directory. 8 | 9 | If it already exists you will be asked if you want to overwrite the file, 10 | if you cancel the overwrite operation the configuration file will open 11 | with the default text editor for .ini files. 12 | 13 | USAGE 14 | ----- 15 | 16 | Check hs-config -h 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /docs/hs-browse.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-browse 5 | 6 | Opens all the URLs are specified in the configuration with the 7 | default web browser available. 8 | 9 | CONFIGURATION 10 | ------------- 11 | 12 | Here's an example configuration: 13 | 14 | [hs-browse] 15 | url1 = www.github.com 16 | url2 = www.stackoverflow.com 17 | url3 = www.facebook.com 18 | url4 = mail.google.com 19 | 20 | 1. URLs 21 | 22 | The URLs. 23 | 24 | USAGE 25 | ----- 26 | 27 | Check hs-browse -h 28 | -------------------------------------------------------------------------------- /src/errors.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module contains all the error raised by hacker-scripts scripts 3 | """ 4 | 5 | 6 | class Error(Exception): 7 | """ Base class for all exceptions """ 8 | pass 9 | 10 | 11 | class ConfigError(Error): 12 | """ 13 | Raised when invalid configuration is encountered 14 | the configuration file 15 | """ 16 | 17 | def __init__(self, message): 18 | self.message = message 19 | 20 | def __srt__(self): 21 | return repr(self.message) 22 | -------------------------------------------------------------------------------- /docs/hs-wallpaper.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-wallpaper 5 | 6 | Scans the given wallpaper directory (including sub-directories) for it's 7 | images and sets a random image from them as your desktop wallpaper. 8 | 9 | CONFIGURATION 10 | ------------- 11 | 12 | Here's an example configuration: 13 | 14 | [hs-wallpaper] 15 | directory = C:\Users\Areeb\Desktop\Wallpapers 16 | 17 | 1. DIRECTORY 18 | 19 | The directory that contains your wallpapers. 20 | 21 | USAGE 22 | ----- 23 | 24 | Check hs-wallpaper -h 25 | -------------------------------------------------------------------------------- /docs/hs-work.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-work 5 | 6 | Opens all the files specified in the configuration with the text editor specified 7 | in the configuration. 8 | 9 | CONFIGURATION 10 | ------------- 11 | 12 | Here's an example configuration: 13 | 14 | [hs-work] 15 | editor = C:\Program Files\Sublime Text 3\sublime_text.exe 16 | project1 = C:\Users\Areeb\Desktop\Python\My Stuff\Projects\Python 3\RSS2IRC 17 | 18 | 1. EDITOR 19 | 20 | The editor/program to open the project files with. 21 | 22 | 2. PROJECTS 23 | 24 | The projects you want to open with the text editor. 25 | 26 | USAGE 27 | ----- 28 | 29 | Check hs-work -h 30 | -------------------------------------------------------------------------------- /docs/hs-start.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-start 5 | 6 | Launches all the programs specified in the configuration. 7 | 8 | "Why would I need this?" 9 | 10 | You can use it to launch the programs you use on a daily basis, if they are more 11 | than 2-3 programs this cmd could be useful. 12 | 13 | CONFIGURATION 14 | ------------- 15 | 16 | Here's an example configuration: 17 | 18 | [hs-start] 19 | program1 = C:\Users\Areeb\Desktop\mIRC\mIRC.exe 20 | 21 | 1. PROGRAMS 22 | 23 | These generally are ".EXEs" or any other executables that you want to launch each 24 | time the cmd/script is run. 25 | 26 | USAGE 27 | ----- 28 | 29 | Check hs-start -h 30 | -------------------------------------------------------------------------------- /docs/hs-music.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-music 5 | 6 | Creates a temporary ".m3u" playlist that contains all the music files located 7 | in the directories (and their sub-directories) specified in the configuration 8 | and launches it with the default music player. 9 | 10 | CONFIGURATION 11 | ------------- 12 | 13 | Here's an example configuration: 14 | 15 | [hs-music] 16 | directory1 = C:\Users\Areeb\Songs\Rock 17 | directory2 = C:\Users\Areeb\Songs\Pop 18 | 19 | 1. DIRECTORIES 20 | 21 | These are the directories which will be scanned for music files and they will 22 | be added to the playlist. 23 | 24 | Supported file types: 25 | ".mp3", ".m4a", ".ogg", ".flac" 26 | 27 | USAGE 28 | ----- 29 | 30 | Check hs-music -h 31 | -------------------------------------------------------------------------------- /tests/test_config.ini: -------------------------------------------------------------------------------- 1 | ; hacker-scripts MOCK configuration file 2 | [hs-backup] 3 | purge = 1 4 | retries = 10 5 | backup_location = D:/ 6 | directory1 = C:/Sample_Dir1 7 | directory2 = C:/Sample_Dir2 8 | 9 | [hs-browse] 10 | url1 = www.sampleweb1.com 11 | url2 = www.sampleweb2.com 12 | 13 | [hs-manage] 14 | extension_set_1 = .txt, .pptx 15 | location_1 = C:/Non_Existing_Dir1 16 | extension_set_2 = .jpg, .png 17 | location_2 = C:/Non_Existing_Dir2 18 | 19 | [hs-music] 20 | directory1 = C:/Sample_Dir1 21 | 22 | [hs-start] 23 | program1 = C:/Sample_Dir1/Sample_Prog1.exe 24 | 25 | [hs-wallpaper] 26 | directory1 = C:/Sample_Dir1 27 | 28 | [hs-work] 29 | editor = C:/Sample_Editor1.exe 30 | project1 = C:/Sample_Dir1 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /delete_playlist.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script is used by hs-music to delete the temporary playlist it creates. 3 | 4 | Since it may take some time for the music player to launch we cannot immediately 5 | delete the playlist.m3u file after calling os.startfile() on it, hence, we wait for 6 | 20 seconds and then delete the playlist. 7 | 8 | This script is separate because if it is put in hs-music.py then the user has to 9 | wait for 20 seconds to use the command line again. 10 | """ 11 | 12 | # Python imports 13 | import os 14 | import time 15 | 16 | WAIT_TIME = 20 # Seconds to wait before deleting the playlist 17 | 18 | 19 | def main(): 20 | print("Deleting temporary playlist in") 21 | # The timer 22 | for i in range(0, WAIT_TIME): 23 | time.sleep(1) 24 | i -= 20 25 | print("%s seconds\r" % i, end="") 26 | 27 | os.remove('playlist.m3u') 28 | 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /add_to_path.py: -------------------------------------------------------------------------------- 1 | """ 2 | Adds the hacker-scripts base directory to PATH 3 | """ 4 | 5 | # Python imports 6 | import os 7 | 8 | # Local imports 9 | from src.initialize import Initialize 10 | 11 | initializer = Initialize() 12 | BASE_DIRECTORY = initializer.BASE_DIRECTORY 13 | # PATH environment variable 14 | PATH = os.environ['PATH'] 15 | 16 | 17 | def main(): 18 | """ Checks if the base directory already exists in PATH, if not then adds it """ 19 | # The base directory 20 | if BASE_DIRECTORY not in PATH.split(os.pathsep): 21 | os.system("setx PATH \"\"") 22 | os.system("setx PATH \"{0};{1}\"".format(PATH, BASE_DIRECTORY)) 23 | 24 | 25 | if __name__ == "__main__": 26 | main() 27 | print(""" 28 | The hacker-scripts has been added to PATH. 29 | ----- 30 | To view the hacker-scripts commands from your terminal, 31 | open a new terminal window and type hs-help. 32 | """) 33 | -------------------------------------------------------------------------------- /docs/hs-desktop.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-desktop 5 | 6 | Got un-organized files all over your desktop? Run hs-desktop to move all of 7 | them in their respective directories. 8 | 9 | CONFIGURATION 10 | ------------- 11 | 12 | Here's an example configuration: 13 | 14 | [hs-desktop] 15 | files_directory = C:\Users\Areeb\Desktop\Files 16 | images_directory = D:\Media\Images 17 | videos_directory = D:\Media\Videos 18 | 19 | 1. FILES_DIRECTORY 20 | 21 | Directory to move your files to. 22 | 23 | Supported file types: 24 | ".txt", ".ppt", ".doc", ".xls" 25 | 26 | 2. IMAGES_DIRECTORY 27 | 28 | Directory to move your images to. 29 | 30 | Supported file types: 31 | ".png", ".jpg", ".gif" 32 | 33 | 3. VIDEOS_DIRECTORY 34 | 35 | Directory to move your videos to. 36 | 37 | Supported file types: 38 | ".avi", ".mp4", ".mkv", ".flv", ".wmv", 39 | ".m4v", ".mpg", ".3gp", ".3g2", ".f4v" 40 | 41 | USAGE 42 | ----- 43 | 44 | hs-desktop [-h] 45 | 46 | Required arguments: 47 | 48 | None 49 | 50 | Optional arguments: 51 | 52 | --h, -h Display this help documentation -------------------------------------------------------------------------------- /docs/hs-manage.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-manage 5 | 6 | Manages all the files in a given directory (passed as an argument) by moving the files 7 | whose extensions are in a given set of extensions (set in the configuration) to the 8 | directory (which again is set in the configuration) associated with them. 9 | 10 | CONFIGURATION 11 | ------------- 12 | 13 | Here's an example configuration: 14 | 15 | [hs-manage] 16 | extension_set_1 = .txt, .ppt, .doc, .xml 17 | location_1 = C:\Users\Areeb\Desktop\Files 18 | extension_set_2 = .jpg, .png, .gif 19 | location_2 = E:\Media\Images 20 | extension_set_3 = .avi, .mp4, .mkv, .flv, .wmv, .m4v, .mpg, .3gp, .3g2, .f4v 21 | location_3 = E:\Media\Videos 22 | 23 | 1. EXTENSION_SETS 24 | 25 | The files with their extensions in extension_set_ will be moved to the directory 26 | in location_. 27 | 28 | 2. LOCATIONS 29 | 30 | Well, it's self explanatory. 31 | 32 | IMPORTANT NOTES: 33 | 34 | - When you enter extensions they must be in the same format as in the above example, 35 | no extra brackets or punctuations. 36 | 37 | - For each extension_set_x option there should be a location_x option and vice versa. 38 | 39 | USAGE 40 | ----- 41 | 42 | Check hs-manage -h -------------------------------------------------------------------------------- /tests/configgenertor.py: -------------------------------------------------------------------------------- 1 | # Python imports 2 | import os 3 | 4 | # Local imports 5 | from src.initialize import Initialize 6 | 7 | 8 | def generate_config_string(): 9 | """ Generates a configuration string with mock values and returns it """ 10 | 11 | initializer = Initialize() 12 | test_directory = os.path.join(initializer.BASE_DIRECTORY, "tests", "test_directory") 13 | test_locations = { 14 | 'ext_dir_1': os.path.join(test_directory, "hs_manage", "extn_dir_1"), 15 | 'ext_dir_2': os.path.join(test_directory, "hs_manage", "extn_dir_2"), 16 | 'music_dir_1': os.path.join(test_directory, "hs_music"), 17 | 'wallpaper_dir_1': os.path.join(test_directory, "hs_wallpaper"), 18 | } 19 | 20 | test_config = """[hs-backup] 21 | purge = 1 22 | retries = 10 23 | backup_location = D:/ 24 | directory1 = C:/Sample_Dir1 25 | directory2 = C:/Sample_Dir2 26 | 27 | [hs-browse] 28 | url1 = www.sampleweb1.com 29 | url2 = www.sampleweb2.com 30 | 31 | [hs-manage] 32 | extension_set_1 = .txt, .pptx 33 | location_1 = %(ext_dir_1)s 34 | extension_set_2 = .jpg, .png 35 | location_2 = %(ext_dir_2)s 36 | 37 | [hs-music] 38 | directory1 = %(music_dir_1)s 39 | 40 | [hs-start] 41 | program1 = C:/Sample_Dir1/Sample_Prog1.exe 42 | 43 | [hs-wallpaper] 44 | directory1 = %(wallpaper_dir_1)s 45 | 46 | [hs-work] 47 | editor = C:/Sample_Editor1.exe 48 | project1 = C:/Sample_Dir1 49 | """ % test_locations 50 | return test_config 51 | -------------------------------------------------------------------------------- /docs/hs-backup.txt: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | ----------- 3 | 4 | hs-backup 5 | 6 | Automatically creates a backup of the directories specified in the configuration 7 | (or the directory supplied as an argument with the --directory parameter, 8 | check usage for more info) 9 | using the windows ROBOCOPY command. 10 | 11 | Each time a backup is complete the log is appended to the backup log file 12 | which can be found in the hacker-scripts directory. 13 | 14 | The log file is automatically cleared after the size exceeds 1 MB. 15 | 16 | CONFIGURATION 17 | ------------- 18 | 19 | Here's an example configuration: 20 | 21 | [hs-backup] 22 | purge = 0 23 | retries = 10 24 | backup_location = D:\ 25 | directory1 = C:\Users\Areeb\Documents\GitHub 26 | directory2 = C:\Users\Areeb\Desktop\Python 27 | directory3 = C:\Users\Areeb\Desktop\Files 28 | 29 | 1. PURGE 30 | 31 | PURGE may have 2 values, either 0 (OFF) or 1 (ON) 32 | 33 | If PURGE is ON then the files that do not exist in the source anymore 34 | will be deleted from the backup location. If you prefer to keep deleted files 35 | on your backup then set it to 0 (OFF). 36 | 37 | 2. RETRIES 38 | 39 | This is the number of times ROBOCOPY should retry the backup if it fails. 40 | In ROBOCOPY by default this value is 1 million (1000000), you probably would 41 | want a lower value on a personal computer. 42 | 43 | 3. BACKUP_LOCATION 44 | 45 | This is where all your files will be backed up to. Usually this would be another 46 | drive. 47 | 48 | 4. DIRECTORIES 49 | 50 | These are the directories that you want to create a backup of, each time the command 51 | is run. 52 | 53 | USAGE 54 | ----- 55 | 56 | Check hs-backup -h 57 | -------------------------------------------------------------------------------- /hs-watch.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 5th September 2017 3 | 4 | """ 5 | Creates a playlist of all the MP4 files in the directory and starts it. 6 | Wrote this one because I watch a lot of anime (downloaded). 7 | """ 8 | 9 | ############################################################################# 10 | # Copyright (C) 2016 Areeb Beigh # 11 | # # 12 | # This program is free software: you can redistribute it and/or modify # 13 | # it under the terms of the GNU General Public License as published by # 14 | # the Free Software Foundation, either version 3 of the License, or # 15 | # (at your option) any later version. # 16 | # # 17 | # This program is distributed in the hope that it will be useful, # 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 20 | # GNU General Public License for more details. # 21 | # # 22 | # You should have received a copy of the GNU General Public License # 23 | # along with this program. If not, see . # 24 | ############################################################################# 25 | 26 | # Python imports 27 | import os 28 | 29 | # Local imports 30 | from src import filetools 31 | 32 | playlist = os.path.join(os.getcwd(), "playlist.m3u") 33 | 34 | with open(playlist, "w") as f: 35 | for file in filetools.natural_sort(os.listdir()): 36 | print(file) 37 | if file.lower().endswith(".mp4"): 38 | f.write(os.path.join(os.getcwd(), file) + "\n") 39 | 40 | os.startfile(playlist) 41 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | hacker-scripts 2 | =============== 3 | 4 | hacker-scripts is a collection of various scripts written in Python that make daily computer tasks easier. It is a great tool 5 | if you are a lazy computer user (like me) and want things done just with a single command from your command line. This software 6 | currently mostly contains scripts that work on Windows OS. 7 | 8 | 9 | Installation 10 | ------------- 11 | 12 | Simply download the hacker-scripts package and run the ``add_to_path.py`` script. This will add the hacker-scripts folder to the 13 | environment variable PATH. After this you should be able to run any of the ``hs-`` prefixed hacker-scripts from the PowerShell 14 | just by typing their name. 15 | 16 | After adding the directory to PATH the next thing you have to do is to configure hacker-scripts. This also is an easy process, 17 | to configure hacker-scripts run the ``hs-config`` command and a new config.ini file will be created in the hacker-scripts 18 | directory. Once this is done you can proceed with the configuration. The configuration also is a straight forward process, the 19 | help docs are all available in the ``docs`` folder, you can refer to those for help. 20 | 21 | Usage 22 | ----- 23 | 24 | Using these scripts is pretty much straight forward. After you've done the installation process you can run any hacker-scripts 25 | command via the command line (preferrable Windows PowerShell). Use `hs-help` to view a list of commands and use the following 26 | syntax to get a detailed help description of a command: 27 | `` -dh`` example: ``hs-music -dh`` 28 | To simply view the syntax of a command use the following syntax: `` -h`` 29 | 30 | Contributing 31 | ------------ 32 | 33 | All contributions are welcomed. You can fork the repo add your own scripts (written in Python3) or bug fixes and make a pull request. 34 | 35 | Cheers :coffee: 36 | 37 | | **Developer:** Areeb Beigh 38 | | **GitHub Repo:** https://github.com/areebbeigh/hacker-scripts 39 | -------------------------------------------------------------------------------- /hs-browse.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 10th April 2016 3 | 4 | """ 5 | Opens all the URLs listed in config.ini [hs-browse] section 6 | """ 7 | 8 | ############################################################################# 9 | # Copyright (C) 2016 Areeb Beigh # 10 | # # 11 | # This program is free software: you can redistribute it and/or modify # 12 | # it under the terms of the GNU General Public License as published by # 13 | # the Free Software Foundation, either version 3 of the License, or # 14 | # (at your option) any later version. # 15 | # # 16 | # This program is distributed in the hope that it will be useful, # 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 19 | # GNU General Public License for more details. # 20 | # # 21 | # You should have received a copy of the GNU General Public License # 22 | # along with this program. If not, see . # 23 | ############################################################################# 24 | 25 | # Python imports 26 | import webbrowser 27 | 28 | # Local imports 29 | from src.initialize import Initialize 30 | from src.configreader import ConfigReader 31 | 32 | initializer = Initialize() 33 | config_file = initializer.config_file 34 | config_reader = ConfigReader(config_file) 35 | main = initializer.basic_main 36 | 37 | # List of URLs to open (will be filled later) 38 | urls = config_reader.read_config("hs-browse") 39 | 40 | 41 | def execute(): 42 | for url in urls: 43 | print(" Opening", url) 44 | # Opens the URL with the default browser 45 | webbrowser.open(url) 46 | 47 | if __name__ == "__main__": 48 | main(execute) 49 | -------------------------------------------------------------------------------- /hs-start.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 10th April 2016 3 | 4 | """ 5 | Starts all the programs in config.ini [hs-start] 6 | """ 7 | 8 | ############################################################################# 9 | # Copyright (C) 2016 Areeb Beigh # 10 | # # 11 | # This program is free software: you can redistribute it and/or modify # 12 | # it under the terms of the GNU General Public License as published by # 13 | # the Free Software Foundation, either version 3 of the License, or # 14 | # (at your option) any later version. # 15 | # # 16 | # This program is distributed in the hope that it will be useful, # 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 19 | # GNU General Public License for more details. # 20 | # # 21 | # You should have received a copy of the GNU General Public License # 22 | # along with this program. If not, see . # 23 | ############################################################################# 24 | 25 | # Python imports 26 | import os 27 | 28 | # Local imports 29 | from src.errors import * 30 | from src.initialize import Initialize 31 | from src.configreader import ConfigReader 32 | 33 | initializer = Initialize() 34 | config_file = initializer.config_file 35 | config_reader = ConfigReader(config_file) 36 | main = initializer.basic_main 37 | # List of programs/files to be opened (will be filled later) 38 | files = config_reader.read_config("hs-start") 39 | 40 | 41 | def execute(): 42 | # At least one program / file must be specified in the config 43 | if len(files) > 0: 44 | for file in files: 45 | if os.path.isfile(file): 46 | print(" Opening", file) 47 | os.startfile(file) 48 | else: 49 | print(" Skipping", file, "since it does not exist") 50 | else: 51 | raise ConfigError("No programs / files specified in the configuration file") 52 | 53 | if __name__ == "__main__": 54 | main(execute) 55 | -------------------------------------------------------------------------------- /hs-work.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 10th April 2016 3 | 4 | """ 5 | Opens all the project files in config.ini [hs-work] with the text editor 6 | specified in config.ini 7 | """ 8 | 9 | ############################################################################# 10 | # Copyright (C) 2016 Areeb Beigh # 11 | # # 12 | # This program is free software: you can redistribute it and/or modify # 13 | # it under the terms of the GNU General Public License as published by # 14 | # the Free Software Foundation, either version 3 of the License, or # 15 | # (at your option) any later version. # 16 | # # 17 | # This program is distributed in the hope that it will be useful, # 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 20 | # GNU General Public License for more details. # 21 | # # 22 | # You should have received a copy of the GNU General Public License # 23 | # along with this program. If not, see . # 24 | ############################################################################# 25 | 26 | # Python imports 27 | import os 28 | 29 | # Local imports 30 | from src.errors import * 31 | from src.initialize import Initialize 32 | from src.configreader import ConfigReader 33 | 34 | initializer = Initialize() 35 | config_file = initializer.config_file 36 | config_reader = ConfigReader(config_file) 37 | main = initializer.basic_main 38 | # List of files and the text editor to open them with 39 | files, editor = config_reader.read_config("hs-work") 40 | 41 | if not editor: 42 | raise ConfigError("No editor specified for the files") 43 | 44 | 45 | def execute(): 46 | if len(files) > 0: 47 | for file in files: 48 | print(" Opening", file) 49 | os.system('START "" "{0}" "{1}"'.format(editor, file)) 50 | 51 | # If no files are specified in config.ini 52 | else: 53 | raise ConfigError("No files specified in the configuration file") 54 | 55 | 56 | if __name__ == "__main__": 57 | main(execute) 58 | -------------------------------------------------------------------------------- /hs-wallpaper.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 10th April 2016 3 | 4 | """ 5 | Chooses a random image file from the directory specified in the config.ini 6 | [hs-wallpaper] section and sets it as the desktop background 7 | """ 8 | 9 | ############################################################################# 10 | # Copyright (C) 2016 Areeb Beigh # 11 | # # 12 | # This program is free software: you can redistribute it and/or modify # 13 | # it under the terms of the GNU General Public License as published by # 14 | # the Free Software Foundation, either version 3 of the License, or # 15 | # (at your option) any later version. # 16 | # # 17 | # This program is distributed in the hope that it will be useful, # 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 20 | # GNU General Public License for more details. # 21 | # # 22 | # You should have received a copy of the GNU General Public License # 23 | # along with this program. If not, see . # 24 | ############################################################################# 25 | 26 | # Python imports 27 | import ctypes 28 | import os 29 | import random 30 | 31 | # Local imports 32 | from src.errors import * 33 | from src.initialize import Initialize 34 | from src.configreader import ConfigReader 35 | 36 | initializer = Initialize() 37 | config_file = initializer.config_file 38 | config_reader = ConfigReader(config_file) 39 | main = initializer.basic_main 40 | # Gets a list of all the wallpapers in the directories (in the config file) 41 | # and in their sub-directories as well 42 | wallpapers = config_reader.read_config("hs-wallpaper") 43 | 44 | 45 | def execute(): 46 | if wallpapers: 47 | # Chooses a random wallpaper from the list of wallpapers 48 | random_wallpaper = random.choice(wallpapers) 49 | print(" Setting", os.path.basename(random_wallpaper), "as desktop wallpaper...") 50 | SPI_SETDESKWALLPAPER = 20 51 | ctypes.windll.user32.SystemParametersInfoW( 52 | SPI_SETDESKWALLPAPER, 53 | 0, 54 | random_wallpaper, 55 | 0) 56 | else: 57 | raise ConfigError("No wallpapers found in the specified directories") 58 | 59 | if __name__ == "__main__": 60 | main(execute) 61 | -------------------------------------------------------------------------------- /src/filetools.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module contains methods that help in working with files 3 | and directories 4 | """ 5 | 6 | ################################################################################# 7 | # Copyright (C) 2016 Areeb Beigh # 8 | # # 9 | # This library is free software; you can redistribute it and/or # 10 | # modify it under the terms of the GNU Lesser General Public # 11 | # License as published by the Free Software Foundation; either # 12 | # version 2.1 of the License, or (at your option) any later version. # 13 | # # 14 | # This library is distributed in the hope that it will be useful, # 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # 17 | # Lesser General Public License for more details. # 18 | # # 19 | # You should have received a copy of the GNU Lesser General Public # 20 | # License along with this library; if not, write to the Free Software # 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 22 | ################################################################################# 23 | 24 | import os 25 | import re 26 | 27 | 28 | def get_all_files(directory, extensions): 29 | """ 30 | Returns a list of all the files from a directory and it's sub-directories with one of the given extensions. 31 | The sentence case of the extensions do not matter. 32 | 33 | Parameters: 34 | directory: 35 | The directory to scan. 36 | 37 | extensions: 38 | A list containing the file extensions 39 | to scan for. 40 | Example: [".png", ".jpg"] 41 | """ 42 | 43 | extensions = [extension.lower() for extension in extensions] 44 | files = [] 45 | 46 | for base, dirs, walk_files in os.walk(directory): 47 | for file in walk_files: 48 | if os.path.splitext(file)[1].lower() in extensions: 49 | files.append(os.path.join(base, file)) 50 | 51 | return files 52 | 53 | # https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/ 54 | def natural_sort(l): 55 | """ Sort the given list in the way that humans expect.""" 56 | convert = lambda text: int(text) if text.isdigit() else text 57 | alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] 58 | l.sort( key=alphanum_key ) 59 | return l 60 | -------------------------------------------------------------------------------- /hs-music.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 10th April 2016 3 | 4 | """ 5 | Makes a temporary playlist of the music files in the directories in config.ini 6 | [hs-music] and opens it with the default media player 7 | """ 8 | 9 | ############################################################################# 10 | # Copyright (C) 2016 Areeb Beigh # 11 | # # 12 | # This program is free software: you can redistribute it and/or modify # 13 | # it under the terms of the GNU General Public License as published by # 14 | # the Free Software Foundation, either version 3 of the License, or # 15 | # (at your option) any later version. # 16 | # # 17 | # This program is distributed in the hope that it will be useful, # 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 20 | # GNU General Public License for more details. # 21 | # # 22 | # You should have received a copy of the GNU General Public License # 23 | # along with this program. If not, see . # 24 | ############################################################################# 25 | 26 | # Python imports 27 | import os 28 | 29 | # Local imports 30 | from src.errors import * 31 | from src.initialize import Initialize 32 | from src.configreader import ConfigReader 33 | 34 | initializer = Initialize() 35 | config_file = initializer.config_file 36 | config_reader = ConfigReader(config_file) 37 | main = initializer.basic_main 38 | 39 | # Gets a list of all the music files in the directories and 40 | # their sub-directories in the configuration file 41 | music_files = config_reader.read_config("hs-music") 42 | 43 | 44 | def execute(): 45 | if music_files: 46 | # Playlist path 47 | playlist = os.path.join(initializer.BASE_DIRECTORY, 'playlist.m3u') 48 | 49 | with open(playlist, 'w') as f: 50 | for file in music_files: 51 | f.write(file + '\n') 52 | 53 | print(" Playing", str(len(music_files)), "music files") 54 | 55 | os.startfile(playlist) 56 | 57 | # Starts the delete_playlist script to delete the temporary playlist 58 | command = "START \"DELETE_PLAYLIST\" /MIN python {}".format( 59 | os.path.join(initializer.BASE_DIRECTORY, "delete_playlist.py")) 60 | os.system(command) 61 | else: 62 | raise ConfigError("No music files found in given directories") 63 | 64 | if __name__ == "__main__": 65 | main(execute) 66 | -------------------------------------------------------------------------------- /tests/test_configreader.py: -------------------------------------------------------------------------------- 1 | # Python imports 2 | import configparser 3 | import os 4 | import unittest 5 | 6 | # Local imports 7 | from src import configreader 8 | from src.initialize import Initialize 9 | from tests.configgenertor import generate_config_string 10 | 11 | initializer = Initialize() 12 | test_directory = os.path.join(initializer.BASE_DIRECTORY, "tests", "test_directory") 13 | test_config = generate_config_string() 14 | 15 | 16 | class ConfigReaderTestCase(unittest.TestCase): 17 | """ 18 | These tests are written for the individual read methods in the 19 | configreader.ConfigReader() module. A mock configuration and 20 | directory tree (tests/test_directory) is used for testing. 21 | """ 22 | 23 | def setUp(self): 24 | self.reader = configreader.ConfigReader("") 25 | self.Config = configparser.ConfigParser() 26 | self.Config.read_string(test_config) 27 | 28 | def test_read_backup(self): 29 | purge, retries, backup_loc, directories = self.reader._read_backup(self.Config) 30 | self.assertEqual(purge, '1') 31 | self.assertEqual(retries, '10') 32 | self.assertEqual(backup_loc, "D:/") 33 | self.assertEqual(directories, ["C:/Sample_Dir1", "C:/Sample_Dir2"]) 34 | 35 | def test_read_browse(self): 36 | urls = self.reader._read_browse(self.Config) 37 | self.assertEqual(urls, ["www.sampleweb1.com", "www.sampleweb2.com"]) 38 | 39 | def test_read_manage(self): 40 | result = self.reader._read_manage(self.Config) 41 | expected_result = { 42 | ('.txt', '.pptx'): os.path.join(test_directory, "hs_manage", "extn_dir_1"), 43 | ('.jpg', '.png'): os.path.join(test_directory, "hs_manage", "extn_dir_2"), 44 | } 45 | self.assertEqual(result, expected_result) 46 | 47 | def test_read_music(self): 48 | result = self.reader._read_music(self.Config) 49 | expected_result = [ 50 | os.path.join(test_directory, "hs_music", "fake_music1.mp3"), 51 | os.path.join(test_directory, "hs_music", "fake_music2.mp3"), 52 | os.path.join(test_directory, "hs_music", "more music", "fake_music3.mp3"), 53 | ] 54 | self.assertEqual(result, expected_result) 55 | 56 | def test_read_start(self): 57 | result = self.reader._read_start(self.Config) 58 | self.assertEqual(result, ["C:/Sample_Dir1/Sample_Prog1.exe"]) 59 | 60 | def test_read_wallpaper(self): 61 | result = self.reader._read_wallpaper(self.Config) 62 | expected_result = [ 63 | os.path.join(test_directory, "hs_wallpaper", "fake_wallpaper1.jpg"), 64 | os.path.join(test_directory, "hs_wallpaper", "fake_wallpaper2.jpg"), 65 | os.path.join(test_directory, "hs_wallpaper", "more wallpapers", "fake_wallpaper3.jpg"), 66 | ] 67 | self.assertEqual(result, expected_result) 68 | 69 | def test_read_work(self): 70 | files, editor = self.reader._read_work(self.Config) 71 | self.assertEqual(files, ["C:/Sample_Dir1"]) 72 | self.assertEqual(editor, "C:/Sample_Editor1.exe") 73 | 74 | 75 | if __name__ == '__main__': 76 | unittest.main() 77 | -------------------------------------------------------------------------------- /src/help.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module is used to display the help content for each command 3 | when the argument --h or --help is passed to that command 4 | """ 5 | 6 | ################################################################################# 7 | # Copyright (C) 2016 Areeb Beigh # 8 | # # 9 | # This library is free software; you can redistribute it and/or # 10 | # modify it under the terms of the GNU Lesser General Public # 11 | # License as published by the Free Software Foundation; either # 12 | # version 2.1 of the License, or (at your option) any later version. # 13 | # # 14 | # This library is distributed in the hope that it will be useful, # 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # 17 | # Lesser General Public License for more details. # 18 | # # 19 | # You should have received a copy of the GNU Lesser General Public # 20 | # License along with this library; if not, write to the Free Software # 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 22 | ################################################################################# 23 | 24 | # Python imports 25 | import os 26 | 27 | os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # Base directory 28 | docs_dir = "docs" 29 | header = os.path.join(docs_dir, "header.txt") 30 | footer = os.path.join(docs_dir, "footer.txt") 31 | arg_tip = os.path.join(docs_dir, "tip1.txt") # Tip for cmds that require arguments 32 | 33 | cmd_docs = { 34 | "hs-backup": "hs-backup.txt", 35 | "hs-browse": "hs-browse.txt", 36 | "hs-config": "hs-config.txt", 37 | "hs-desktop": "hs-desktop.txt", 38 | "hs-manage": "hs-manage.txt", 39 | "hs-music": "hs-music.txt", 40 | "hs-schedule": "hs-schedule.txt", 41 | "hs-start": "hs-start.txt", 42 | "hs-wallpaper": "hs-wallpaper.txt", 43 | "hs-work": "hs-work.txt", 44 | } 45 | 46 | arg_cmds = ["hs-backup", "hs-manage", "hs-schedule"] # CMDs that require arguments 47 | 48 | 49 | def more(file_name): 50 | """ 51 | Displays the text in the given file name on the terminal using the "more" 52 | terminal command. 53 | """ 54 | 55 | os.system("more \"{}\"".format(file_name)) 56 | 57 | 58 | def display_help(cmd_name): 59 | """ 60 | Displays help document for given cmd name. 61 | """ 62 | 63 | cmd_name = os.path.basename(cmd_name) 64 | doc = '' 65 | try: 66 | doc = os.path.join(docs_dir, cmd_docs[cmd_name]) 67 | except KeyError: 68 | print("No help available for", cmd_name) 69 | exit() 70 | 71 | if os.path.exists(doc): 72 | more(header) 73 | more(doc) 74 | if cmd_name in arg_cmds: 75 | more(arg_tip) 76 | more(footer) 77 | else: 78 | print("No help available for", cmd_name) 79 | -------------------------------------------------------------------------------- /src/initialize.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script is used in most of the hacker-script programs to do the initial stuff 3 | """ 4 | 5 | ################################################################################# 6 | # Copyright (C) 2016 Areeb Beigh # 7 | # # 8 | # This library is free software; you can redistribute it and/or # 9 | # modify it under the terms of the GNU Lesser General Public # 10 | # License as published by the Free Software Foundation; either # 11 | # version 2.1 of the License, or (at your option) any later version. # 12 | # # 13 | # This library is distributed in the hope that it will be useful, # 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # 16 | # Lesser General Public License for more details. # 17 | # # 18 | # You should have received a copy of the GNU Lesser General Public # 19 | # License along with this library; if not, write to the Free Software # 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 21 | ################################################################################# 22 | 23 | # Python imports 24 | import argparse 25 | import os 26 | import sys 27 | 28 | # Local imports 29 | from src import help 30 | 31 | 32 | class Initialize: 33 | """ 34 | Holds string properties (the base directory, white space and 35 | the configuration file name) and methods for other important 36 | initializations 37 | """ 38 | 39 | def __init__(self): 40 | # Sets the base directory 41 | self._BASE_DIRECTORY = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 42 | # The configuration file name 43 | self._config_file = "config.ini" 44 | 45 | @property 46 | def BASE_DIRECTORY(self): 47 | return self._BASE_DIRECTORY 48 | 49 | @property 50 | def config_file(self): 51 | return self._config_file 52 | 53 | def change_to_base_dir(self): 54 | """ Changes the current working directory to the base directory """ 55 | os.chdir(self.BASE_DIRECTORY) 56 | 57 | def basic_main(self, execute_method): 58 | """ 59 | A simple form of the main() function used by most of the hacker-scripts 60 | 61 | Parameters: 62 | execute_method: 63 | The method to execute after finishing with the main method. 64 | This method is executed only if any of the help arguments are not passed while 65 | executing a hacker-script. 66 | """ 67 | parser = argparse.ArgumentParser(add_help=True) 68 | parser.add_argument('-dhelp', 69 | '--dhelp', 70 | action='store_true', 71 | help='displays detailed help for this hacker-script') 72 | args = parser.parse_args() 73 | 74 | if args.dhelp: 75 | cmd = sys.argv[0].partition(".")[0] 76 | help.display_help(cmd) 77 | return 78 | 79 | execute_method() 80 | -------------------------------------------------------------------------------- /hs-help.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 23rd June 2016 3 | 4 | """ 5 | Prints a brief help documentation to the terminal 6 | """ 7 | 8 | 9 | ############################################################################# 10 | # Copyright (C) 2016 Areeb Beigh # 11 | # # 12 | # This program is free software: you can redistribute it and/or modify # 13 | # it under the terms of the GNU General Public License as published by # 14 | # the Free Software Foundation, either version 3 of the License, or # 15 | # (at your option) any later version. # 16 | # # 17 | # This program is distributed in the hope that it will be useful, # 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 20 | # GNU General Public License for more details. # 21 | # # 22 | # You should have received a copy of the GNU General Public License # 23 | # along with this program. If not, see . # 24 | ############################################################################# 25 | 26 | def main(): 27 | print(""" 28 | Python hacker-scripts by Areeb - github.com/areebbeigh/hacker-scripts (Feel free to contribute) 29 | 30 | This is a collection of mini-scripts written in Python intended to make 31 | frequently used or random tasks such as playing music, launching programs you use 32 | frequently, opening the pages you browse daily etc easier just with a single command 33 | through your terminal. 34 | 35 | --------- 36 | Currently available commands: 37 | 38 | > hs-backup Creates a backup of all the files in the backup location, both are specified in the config 39 | > hs-browse Opens the URLs in the configuration file 40 | > hs-config Creates (or overwrites) a config.ini file in the hacker-scripts directory 41 | > hs-help Displays this help documentation 42 | > hs-manage Manages all the files in a given directory by moving those files to their respective locations 43 | > hs-music Creates and plays a temporary playlist of music files in the directories in the configuration 44 | > hs-schedule Creates a new windows scheduled task that executes a hacker-scripts cmd at a time in the future 45 | > hs-start Launches the programs listed in the configuration 46 | > hs-wallpaper Chooses and sets a random wallpaper from the wallpapers directory specified in the configuration 47 | > hs-work Opens all the files specified with the text editor (both are set in the configuration) 48 | 49 | Most the above scripts depend on the config.ini file located in the hacker-scripts directory. 50 | If you don't find a config.ini file in your hacker-scripts directory run hs-config to create one. 51 | 52 | The help statements for each script above is just a compact version, to view the full description, 53 | configuration examples and usage details of a script use: 54 | 55 | " -dh" 56 | 57 | Ex: "hs-music -h" will display hs-music's help documentation. 58 | """) 59 | 60 | 61 | if __name__ == "__main__": 62 | main() 63 | -------------------------------------------------------------------------------- /hs-desktop.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 10th April 2016 3 | 4 | """ 5 | Manages your desktop by automatically placing different files to their 6 | respective directories in config.ini [hs-desktop] 7 | """ 8 | 9 | """ 10 | TODO: 11 | 12 | Users should be able to define their own extensions and the locations to which 13 | those extension file types should be moved to. 14 | 15 | Example config: 16 | extensions1 = [".txt", ".doc", ".ppt"] 17 | location1 = C:\\Users\\Areeb\\Documents 18 | 19 | Syntax: 20 | 21 | hs-manage -d :: Directory to organize files of 22 | hs-manage -c or :: Manage files in current directory 23 | """ 24 | 25 | # Python imports 26 | import argparse 27 | import os 28 | import sys 29 | 30 | # Local imports 31 | from src import help 32 | from src.errors import * 33 | from src.initialize import Initialize 34 | from src.configreader import ConfigReader 35 | 36 | initializer = Initialize() 37 | white_space = initializer.white_space 38 | config_file = initializer.config_file 39 | config_reader = ConfigReader(config_file) 40 | # Gets the path to Desktop 41 | desktop = os.path.join(os.environ['USERPROFILE'], "Desktop") 42 | 43 | # Paths/Directories for different file types 44 | paths = config_reader.read_config("hs-desktop") 45 | 46 | 47 | 48 | def main(): 49 | parser = argparse.ArgumentParser(add_help=False) 50 | parser.add_argument('--help', 51 | '-help', 52 | action='store_true') 53 | 54 | args = parser.parse_args() 55 | 56 | if args.help: 57 | cmd = sys.argv[0].partition(".")[0] 58 | help.display_help(cmd) 59 | return 60 | 61 | execute() 62 | 63 | 64 | 65 | ''' 66 | def execute(): 67 | if "" not in paths.values(): 68 | files = os.listdir(desktop) 69 | 70 | for file in files: 71 | # Creates a full path to the file in desktop 72 | file_page = os.path.join(desktop, file) 73 | 74 | if not os.path.isdir(file): 75 | # Splits file path and file extension 76 | file_name, file_extn = os.path.splitext(file_page) 77 | 78 | # Further we check if the extension of the file is mentioned in 79 | # any of the extension lists above and then we put the file in 80 | # the directory (from dict 'paths') matching the file type 81 | 82 | # Check for images 83 | if file_extn.lower() in image_extns: 84 | new_location = os.path.join(paths["images"], file) 85 | # Check for videos 86 | elif file_extn.lower() in video_extns: 87 | new_location = os.path.join(paths["videos"], file) 88 | # Check for text files 89 | elif file_extn.lower() in text_file_extns: 90 | new_location = os.path.join(paths["textFiles"], file) 91 | # If the file type is unknown to the program then we skip it 92 | else: 93 | new_location = None 94 | 95 | # If the file type is not unknown then ... 96 | if new_location: 97 | try: 98 | # This moves the file to "new_location" 99 | os.rename(file_page, new_location) 100 | print("{0} Moved {1}".format( 101 | white_space, 102 | os.path.basename(file_page))) 103 | # If a file with the same name already exists then we rename 104 | # the file we're operating on 105 | except WindowsError: 106 | file_name, file_extn = os.path.splitext(new_location) 107 | count = 1 108 | # Randomly append an integer to the end of the file name 109 | while os.path.exists(new_location): 110 | new_location = ( 111 | file_name + 112 | " (" + 113 | str(count) + 114 | ")" + 115 | file_extn 116 | ) 117 | count += 1 118 | 119 | # Moves the file to "new_location" 120 | os.rename(file_page, new_location) 121 | print("{0} Renamed {1} to {2} since {1} already exists in destination folder".format( 122 | white_space, 123 | os.path.basename(file), 124 | os.path.basename(new_location))) 125 | else: 126 | raise ConfigError("All paths are not specified in the configuration file") 127 | ''' 128 | 129 | 130 | if __name__ == "__main__": 131 | main() 132 | -------------------------------------------------------------------------------- /hs-manage.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 7th August 2016 3 | 4 | """ 5 | Manages all files that have one of a given set of extensions in a directory 6 | by moving them to their respective correct locations (config dependent) 7 | """ 8 | 9 | ############################################################################# 10 | # Copyright (C) 2016 Areeb Beigh # 11 | # # 12 | # This program is free software: you can redistribute it and/or modify # 13 | # it under the terms of the GNU General Public License as published by # 14 | # the Free Software Foundation, either version 3 of the License, or # 15 | # (at your option) any later version. # 16 | # # 17 | # This program is distributed in the hope that it will be useful, # 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 20 | # GNU General Public License for more details. # 21 | # # 22 | # You should have received a copy of the GNU General Public License # 23 | # along with this program. If not, see . # 24 | ############################################################################# 25 | 26 | # Python imports 27 | import argparse 28 | import os 29 | import sys 30 | 31 | # Local imports 32 | from src import help 33 | from src.initialize import Initialize 34 | from src.configreader import ConfigReader 35 | 36 | initializer = Initialize() 37 | config_file = initializer.config_file 38 | config_reader = ConfigReader(config_file) 39 | # Gets a Extensions-Directory key-value pair 40 | loc_pairs = config_reader.read_config("hs-manage") 41 | 42 | 43 | def main(): 44 | parser = argparse.ArgumentParser(add_help=True, allow_abbrev=False) 45 | group = parser.add_mutually_exclusive_group(required=True) 46 | group.add_argument('-d', 47 | '--directory', 48 | nargs=1, 49 | metavar='DIR', 50 | help='directory to manage files in') 51 | group.add_argument('-dh', 52 | '--dhelp', 53 | action='store_true', 54 | help='displays detailed help for this hacker-script') 55 | 56 | args = parser.parse_args() 57 | 58 | if args.directory: 59 | execute(args.directory[0]) 60 | elif args.dhelp: 61 | cmd = sys.argv[0].partition(".")[0] 62 | help.display_help(cmd) 63 | return 64 | 65 | 66 | def execute(directory): 67 | if not os.path.isdir(directory): 68 | print("Invalid directory:", directory) 69 | return 70 | 71 | for file in os.listdir(directory): 72 | for extn_tuple in loc_pairs: 73 | if ("." + file.partition(".")[2]) in extn_tuple: 74 | new_directory = loc_pairs[extn_tuple] 75 | old_location = os.path.join(directory, file) 76 | new_location = os.path.join(new_directory, file) 77 | i = 0 # Number assigned at the end of the file if it already exists 78 | while os.path.exists(new_location): 79 | i += 1 80 | name, dummy, extension = file.partition(".") 81 | _file = name + "(" + str(i) + ")" + "." + extension 82 | new_location = os.path.join(new_directory, _file) 83 | if not os.path.exists(new_location): 84 | print(" Renaming {0} to {1} since file already exists".format( 85 | file, 86 | os.path.basename(new_location) 87 | )) 88 | # Uses windows shell command if the new location drive is different 89 | # from the old location drive because Python's os.rename can't move files 90 | # from one drive to another on windows 91 | if os.path.splitdrive(new_location)[0] == os.path.splitdrive(old_location)[0]: 92 | os.rename(old_location, new_location) 93 | else: 94 | print(" -> Other drive detected, using windows move command") 95 | command = "move /-Y \"{0}\" \"{1}\"".format( 96 | old_location, 97 | new_location 98 | ) # /-Y - prompt to overwrite (which shouldn't occur actually but eh) 99 | os.system(command) 100 | print(" Moved {0} to {1}".format( 101 | file, 102 | new_directory 103 | )) 104 | 105 | 106 | if __name__ == "__main__": 107 | main() 108 | -------------------------------------------------------------------------------- /hs-backup.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 28th July 2016 3 | 4 | """ 5 | Automatically creates a backup of all the files in the backup location. Both, 6 | the files and the backup location are specified in the configuration 7 | """ 8 | 9 | ############################################################################# 10 | # Copyright (C) 2016 Areeb Beigh # 11 | # # 12 | # This program is free software: you can redistribute it and/or modify # 13 | # it under the terms of the GNU General Public License as published by # 14 | # the Free Software Foundation, either version 3 of the License, or # 15 | # (at your option) any later version. # 16 | # # 17 | # This program is distributed in the hope that it will be useful, # 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 20 | # GNU General Public License for more details. # 21 | # # 22 | # You should have received a copy of the GNU General Public License # 23 | # along with this program. If not, see . # 24 | ############################################################################# 25 | 26 | # Python imports 27 | import argparse 28 | import os 29 | import sys 30 | 31 | # Local imports 32 | from src import help 33 | from src.errors import * 34 | from src.initialize import Initialize 35 | from src.configreader import ConfigReader 36 | 37 | initializer = Initialize() 38 | config_file = initializer.config_file 39 | config_reader = ConfigReader(config_file) 40 | 41 | 42 | def main(): 43 | parser = argparse.ArgumentParser(add_help=True, allow_abbrev=False) 44 | group = parser.add_mutually_exclusive_group() 45 | group.add_argument('-d', 46 | '--directory', 47 | metavar='DIR', 48 | nargs=1, 49 | help='backup location') 50 | group.add_argument('-dh', 51 | '--dhelp', 52 | action='store_true', 53 | help='displays detailed help for this hacker-script') 54 | args = parser.parse_args() 55 | 56 | if args.dhelp: 57 | cmd = sys.argv[0].partition(".")[0] 58 | help.display_help(cmd) 59 | return 60 | 61 | if args.directory: 62 | execute(args.directory[0]) 63 | else: 64 | execute() 65 | 66 | 67 | def is_valid_config(purge, retries, backup_location, files): 68 | """Takes all options in the "hs-backup" section as parameters and returns 69 | True if they are valid, else raises a ConfigError""" 70 | 71 | try: 72 | purge = int(purge) 73 | if not (purge == 0 or purge == 1): 74 | raise ValueError 75 | except ValueError: 76 | raise ConfigError("Value of purge must be either 0 or 1") 77 | 78 | try: 79 | retries = int(retries) 80 | if not (retries > 0): 81 | raise ValueError 82 | except ValueError: 83 | raise ConfigError("Value of retries must be an integer greater than 0") 84 | 85 | if not os.path.isdir(backup_location): 86 | raise ConfigError("Value of backup_location must be a valid directory)") 87 | 88 | for file in files: 89 | if not os.path.isdir(file): 90 | raise ConfigError("{} is not a directory".format(file)) 91 | 92 | return True 93 | 94 | 95 | def execute(backup_location=None): 96 | if not backup_location: 97 | purge, retries, backup_location, directories = config_reader.read_config("hs-backup") 98 | else: 99 | purge, retries, dummy, directories = config_reader.read_config("hs-backup") 100 | 101 | print(" Backing up all files to", backup_location) 102 | log_file = "backup_log.txt" 103 | max_log_size = 1 * 1024 * 1024 # Default 1 MB 104 | 105 | if is_valid_config(purge, retries, backup_location, directories): 106 | purge = int(purge) 107 | retries = int(retries) 108 | 109 | for file in directories: 110 | backup = os.path.join(backup_location, os.path.basename(file)) 111 | if not os.path.exists(backup): 112 | os.makedirs(backup) 113 | src = file 114 | dst = backup 115 | print(" " + file, backup, sep=" -> ", end="") 116 | # Removes the log file if it gets larger than max_log_size (default 1 MB) 117 | try: 118 | if os.path.getsize(log_file) > max_log_size: 119 | os.remove(log_file) 120 | except FileNotFoundError: 121 | pass 122 | 123 | if purge == 0: 124 | command = "ROBOCOPY /LOG+:\"{0}\" /V /E /R:{1} \"{2}\" \"{3}\"".format( 125 | log_file, 126 | retries, 127 | src, 128 | dst) 129 | else: 130 | command = "ROBOCOPY /LOG+:\"{0}\" /V /E /PURGE /R:{1} \"{2}\" \"{3}\"".format( 131 | log_file, 132 | retries, 133 | src, 134 | dst) 135 | 136 | os.system(command) 137 | print() 138 | 139 | if __name__ == "__main__": 140 | main() 141 | -------------------------------------------------------------------------------- /hs-config.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 11th June 2016 3 | 4 | """ 5 | This script creates (or overwrites) a config.ini file with the default 6 | settings which has to be edited later, if config already exists and 7 | overwriting is canceled it simply opens the config file in the default 8 | application 9 | """ 10 | 11 | ############################################################################# 12 | # Copyright (C) 2016 Areeb Beigh # 13 | # # 14 | # This program is free software: you can redistribute it and/or modify # 15 | # it under the terms of the GNU General Public License as published by # 16 | # the Free Software Foundation, either version 3 of the License, or # 17 | # (at your option) any later version. # 18 | # # 19 | # This program is distributed in the hope that it will be useful, # 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 22 | # GNU General Public License for more details. # 23 | # # 24 | # You should have received a copy of the GNU General Public License # 25 | # along with this program. If not, see . # 26 | ############################################################################# 27 | 28 | # Python imports 29 | import argparse 30 | import configparser 31 | import os 32 | import sys 33 | 34 | # Local imports 35 | from src import help 36 | from src.initialize import Initialize 37 | 38 | initializer = Initialize() 39 | # hacker-scripts base directory 40 | BASE_DIRECTORY = initializer.BASE_DIRECTORY 41 | # Full path to the config file 42 | config_file = os.path.join(BASE_DIRECTORY, initializer.config_file) 43 | Config = configparser.ConfigParser() 44 | Config.read(config_file) 45 | # Default path to sublime text editor 3 on Windows 46 | editor_path = "C:\\Program Files\\Sublime Text 3\\sublime_text.exe" 47 | 48 | if not os.path.exists(editor_path): 49 | editor_path = "" 50 | 51 | 52 | def main(): 53 | parser = argparse.ArgumentParser(add_help=False) 54 | parser.add_argument('--help', 55 | '-help', 56 | action='store_true') 57 | 58 | args = parser.parse_args() 59 | 60 | if args.help: 61 | cmd = sys.argv[0].partition(".")[0] 62 | help.display_help(cmd) 63 | return 64 | 65 | if os.path.isfile(config_file): 66 | print("The file config.ini already exists, do you want to continue and " + 67 | "over-write the file with new settings? (y/N)") 68 | 69 | action = input().upper() 70 | 71 | if action == "Y" or action == "YES": 72 | create_file() 73 | else: 74 | os.startfile(config_file, 'edit') # Opens the file for editing 75 | sys.exit(0) 76 | else: 77 | create_file() 78 | 79 | 80 | def create_file(): 81 | """Creates a new configuration file with default values""" 82 | 83 | with open(config_file, "w") as f: 84 | f.write("; hacker-scripts configuration file\n") 85 | 86 | # Add sections and parameters the the config file 87 | Config.add_section("hs-backup") 88 | Config.set("hs-backup", "purge", "") 89 | Config.set("hs-backup", "retries", "") 90 | Config.set("hs-backup", "backup_location", "") 91 | Config.set("hs-backup", "directory1", "") 92 | Config.set("hs-backup", "directory2", "") 93 | Config.set("hs-backup", "directory3", "") 94 | 95 | Config.add_section("hs-browse") 96 | Config.set("hs-browse", "url1", "") 97 | Config.set("hs-browse", "url2", "") 98 | Config.set("hs-browse", "url3", "") 99 | 100 | Config.add_section("hs-manage") 101 | Config.set("hs-manage", "extension_set_1", ".txt, .ppt, .doc, .xml") 102 | Config.set("hs-manage", "location_1", "") 103 | Config.set("hs-manage", "extension_set_2", ".jpg, .png, .gif") 104 | Config.set("hs-manage", "location_2", "") 105 | Config.set("hs-manage", "extension_set_3", ".avi, .mp4, .mkv, .flv, .wmv, .m4v, .mpg, .3gp, .3g2, .f4v") 106 | Config.set("hs-manage", "location_3", "") 107 | 108 | Config.add_section("hs-music") 109 | Config.set("hs-music", "directory1", "") 110 | Config.set("hs-music", "directory2", "") 111 | Config.set("hs-music", "directory3", "") 112 | 113 | Config.add_section("hs-start") 114 | Config.set("hs-start", "program1", "") 115 | Config.set("hs-start", "program2", "") 116 | Config.set("hs-start", "program3", "") 117 | 118 | Config.add_section("hs-wallpaper") 119 | Config.set("hs-wallpaper", "directory1", "") 120 | Config.set("hs-wallpaper", "directory2", "") 121 | Config.set("hs-wallpaper", "directory3", "") 122 | 123 | Config.add_section("hs-work") 124 | Config.set( 125 | "hs-work", 126 | "editor", 127 | editor_path) 128 | Config.set("hs-work", "project1", "") 129 | Config.set("hs-work", "project2", "") 130 | Config.set("hs-work", "project3", "") 131 | 132 | Config.write(f) 133 | 134 | print("Config file has been created at " + config_file) 135 | print("You can go ahead and configure the file.") 136 | os.startfile('config.ini', 'edit') 137 | sys.exit(0) 138 | 139 | 140 | main() 141 | -------------------------------------------------------------------------------- /hs-schedule.py: -------------------------------------------------------------------------------- 1 | # Author: Areeb Beigh 2 | # Created: 23rd July 2016 3 | 4 | """ 5 | This script creates a new windows scheduled task that executes a hacker-scripts 6 | COMMAND script at a time in the future specified by the user 7 | 8 | Command used: SCHTASKS 9 | """ 10 | 11 | ############################################################################# 12 | # Copyright (C) 2016 Areeb Beigh # 13 | # # 14 | # This program is free software: you can redistribute it and/or modify # 15 | # it under the terms of the GNU General Public License as published by # 16 | # the Free Software Foundation, either version 3 of the License, or # 17 | # (at your option) any later version. # 18 | # # 19 | # This program is distributed in the hope that it will be useful, # 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 22 | # GNU General Public License for more details. # 23 | # # 24 | # You should have received a copy of the GNU General Public License # 25 | # along with this program. If not, see . # 26 | ############################################################################# 27 | 28 | # Python imports 29 | import argparse 30 | import calendar 31 | import os 32 | import re 33 | import sys 34 | import time 35 | 36 | # Local imports 37 | from src import help 38 | from src.initialize import Initialize 39 | 40 | initializer = Initialize() 41 | 42 | 43 | def main(): 44 | parser = argparse.ArgumentParser(add_help=True, allow_abbrev=False) 45 | group = parser.add_mutually_exclusive_group(required=True) 46 | group.add_argument('-a', 47 | '--action', 48 | choices=['add', 'del'], 49 | help='add/del scheduled tasks') 50 | group.add_argument('-dh', 51 | '--dhelp', 52 | action='store_true', 53 | help='displays detailed help for this hacker-script') 54 | args = parser.parse_args() 55 | 56 | if args.dhelp: 57 | cmd = sys.argv[0].partition(".")[0] 58 | help.display_help(cmd) 59 | return 60 | elif args.action == "add": 61 | add_task() 62 | else: 63 | del_task() 64 | 65 | 66 | def get_current_time(): 67 | """ Returns the current time in 24 hr format """ 68 | 69 | return time.strftime("%H:%M") 70 | 71 | 72 | def get_current_date(): 73 | """ Returns the current date in MM/DD/YYYY format """ 74 | 75 | return time.strftime("%m/%d/%Y") 76 | 77 | 78 | def is_valid_time(given_time, today): 79 | """ 80 | Given a time string this function checks if the given time is 81 | in the future today (if "today" is true) else just validates the time 82 | """ 83 | 84 | given_time = given_time.split(":") 85 | current_time = get_current_time().split(":") 86 | 87 | given_hour = int(given_time[0]) 88 | given_minute = int(given_time[1]) 89 | 90 | current_hour = int(current_time[0]) 91 | current_minute = int(current_time[1]) 92 | 93 | if today: 94 | if given_hour < 24 and given_minute <= 59: 95 | return ( 96 | (given_hour > current_hour) or 97 | (given_hour == current_hour and given_minute > current_minute) 98 | ) 99 | else: 100 | return given_hour < 24 and given_minute <= 59 101 | 102 | return False 103 | 104 | 105 | def is_valid_date(given_date): 106 | """ 107 | Given a date string this function checks if the date is in the future 108 | """ 109 | 110 | given_date = given_date.split("/") 111 | current_date = get_current_date().split("/") 112 | 113 | given_day = int(given_date[1]) 114 | given_month = int(given_date[0]) 115 | given_year = int(given_date[2]) 116 | 117 | current_day = int(current_date[1]) 118 | current_month = int(current_date[0]) 119 | current_year = int(current_date[2]) 120 | 121 | try: 122 | calendar.weekday(given_year, given_month, given_day) 123 | except ValueError: 124 | return False 125 | 126 | return ( 127 | (given_year == current_year and given_month == current_month and given_day > current_day) or 128 | (given_year == current_year and given_month > current_month) or 129 | (given_year > current_year)) 130 | 131 | 132 | def add_task(): 133 | """ 134 | Takes all the information about the task to be scheduled and 135 | creates the scheduled task 136 | """ 137 | 138 | commands = [] 139 | blank_line = r"^\s+$" 140 | 141 | # List of ALL the files present in the scripts directory 142 | scripts = os.listdir(os.getcwd()) 143 | 144 | for script in scripts: 145 | # Appends all the script names that have "hs-" prefix and ".py" extension 146 | # to commands after removing the extension from the script name 147 | 148 | if script[0:3] == "hs-" and script.endswith(".py"): 149 | cmd_name = script.partition(".")[0] 150 | commands.append(cmd_name) 151 | 152 | while True: 153 | task_name = input(" Task name: ") 154 | 155 | if task_name: 156 | break 157 | else: 158 | print(" Invalid task name") 159 | 160 | while True: 161 | cmd_name = input(" Command name: ") 162 | 163 | if cmd_name in commands: 164 | break 165 | else: 166 | print(" Invalid command") 167 | 168 | while True: 169 | date = input(" Date (leave blank if today) [MM/DD/YYYY]: ") 170 | 171 | if (re.search(blank_line, date) or date == "") or is_valid_date(date): 172 | break 173 | else: 174 | print(" Invalid date") 175 | 176 | if re.search(blank_line, date) or date == "": 177 | date = get_current_date() 178 | 179 | while True: 180 | task_time = input(" Time [HH:MM]: ") 181 | 182 | if date == get_current_date(): 183 | check = is_valid_time(task_time, True) 184 | else: 185 | check = is_valid_time(task_time, False) 186 | 187 | if check: 188 | break 189 | else: 190 | print(" Invalid time") 191 | 192 | cmd_name = os.path.join(os.getcwd(), cmd_name + ".py") 193 | command = "SCHTASKS /CREATE /SC ONCE /TN {0} /SD {1} /ST {2} /TR \"python '{3}'\"".format( 194 | task_name, 195 | date, 196 | task_time, 197 | cmd_name) 198 | 199 | os.system(command) 200 | 201 | 202 | def del_task(): 203 | """ 204 | Asks the user for the task name to delete and attempts to delete 205 | that task 206 | """ 207 | 208 | while True: 209 | task_name = input(" Enter task name: ") 210 | 211 | if task_name: 212 | break 213 | else: 214 | print(" Invalid task name") 215 | 216 | command = "SCHTASKS /DELETE /TN", task_name 217 | 218 | os.system(command) 219 | 220 | 221 | if __name__ == "__main__": 222 | main() 223 | -------------------------------------------------------------------------------- /src/configreader.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module to read the configuration of different hacker-scripts from the 3 | given configuration file and return the results 4 | """ 5 | 6 | ################################################################################# 7 | # Copyright (C) 2016 Areeb Beigh # 8 | # # 9 | # This library is free software; you can redistribute it and/or # 10 | # modify it under the terms of the GNU Lesser General Public # 11 | # License as published by the Free Software Foundation; either # 12 | # version 2.1 of the License, or (at your option) any later version. # 13 | # # 14 | # This library is distributed in the hope that it will be useful, # 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # 17 | # Lesser General Public License for more details. # 18 | # # 19 | # You should have received a copy of the GNU Lesser General Public # 20 | # License along with this library; if not, write to the Free Software # 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 22 | ################################################################################# 23 | 24 | # Python imports 25 | import configparser 26 | import os 27 | import re 28 | 29 | # Local imports 30 | from src.filetools import get_all_files 31 | from src.initialize import Initialize 32 | from src.errors import * 33 | 34 | initializer = Initialize() 35 | 36 | 37 | class ConfigReader: 38 | # Read method names for each hacker-script 39 | readMethods = { 40 | "hs-backup": "_read_backup", 41 | "hs-browse": "_read_browse", 42 | "hs-manage": "_read_manage", 43 | "hs-music": "_read_music", 44 | "hs-start": "_read_start", 45 | "hs-wallpaper": "_read_wallpaper", 46 | "hs-work": "_read_work", 47 | } 48 | 49 | def __init__(self, config_file): 50 | """ 51 | Creates a configparser.ConfigParser() object and reads the given 52 | configuration file 53 | 54 | Parameters: 55 | config_file: 56 | The configuration file. 57 | """ 58 | 59 | # Switches to hacker-scripts base directory 60 | initializer.change_to_base_dir() 61 | # Loads the configuration file 62 | self.Config = configparser.ConfigParser() 63 | self.Config.read(config_file) 64 | 65 | def read_config(self, script): 66 | """ 67 | Calls the appropriate read method to read the configuration 68 | of the given script, returns None if no method is available 69 | 70 | Parameters: 71 | script: 72 | The hacker-script of which the configuration is 73 | to be read. 74 | Example: "hs-music" 75 | """ 76 | 77 | if script not in self.readMethods: 78 | return None 79 | 80 | return eval("self." + self.readMethods[script])(self.Config) 81 | 82 | def _read_backup(self, config): 83 | """ 84 | Reads hs-backup configuration and returns a tuple of 85 | configuration values 86 | """ 87 | 88 | purge = config.get("hs-backup", "purge") 89 | retries = config.get("hs-backup", "retries") 90 | backup_location = config.get("hs-backup", "backup_location") 91 | directories = [] 92 | 93 | for option in config.options("hs-backup"): 94 | value = config.get("hs-backup", option) 95 | if option[0:9] == "directory" and value: 96 | directories.append(value) 97 | 98 | return purge, retries, backup_location, directories 99 | 100 | def _read_browse(self, config): 101 | """ 102 | Reads hs-browse configuration and returns a list of 103 | urls 104 | """ 105 | 106 | urls = [] 107 | 108 | for option in config.options("hs-browse"): 109 | url = config.get("hs-browse", option) 110 | if url: 111 | urls.append(url) 112 | 113 | return urls 114 | 115 | def _read_manage(self, config): 116 | """ 117 | Reads the hs-manage configuration values and returns them 118 | """ 119 | 120 | extensions = {} # key - (option): value - (extensions tuple) 121 | locations = {} # key - (option): value - (directory path) 122 | result = {} # key - (extensions tuple): value - (directory path) 123 | extension_re = re.compile("^extension_set_(\d+)$") # Example: extension_set_1, extension_set_17 124 | location_re = re.compile("^location_(\d+)$") # Example: location_1, location_17 125 | 126 | for option in config.options("hs-manage"): 127 | ext_match = extension_re.search(option) 128 | opt_match = location_re.search(option) 129 | value = config.get("hs-manage", option) 130 | 131 | if ext_match: 132 | extensions[option] = tuple(value.replace(" ", "").split(",")) 133 | elif opt_match: 134 | locations[option] = value 135 | else: 136 | raise ConfigError("Invalid option name: '{}'".format(option)) 137 | 138 | for i in range(len(extensions)): 139 | i += 1 140 | extension_set = extensions.get("extension_set_" + str(i), None) 141 | location = locations.get("location_" + str(i), None) 142 | if extension_set and location: 143 | # Check if the location is a directory 144 | if not os.path.isdir(location): 145 | raise ConfigError("Invalid directory: {}".format(location)) 146 | # Check if the extensions are in the proper format 147 | for extension in extension_set: 148 | if not re.search(r"^\.[\w]+$", extension): 149 | raise ConfigError("Invalid extension: {}".format(extension)) 150 | # If no error occurs then add the location-extensions pair to results 151 | result[tuple(extension_set)] = location 152 | else: 153 | raise ConfigError("Invalid extensions-location pair: ({0})-{1}".format( 154 | extension_set, 155 | location)) 156 | 157 | return result 158 | 159 | def _read_music(self, config): 160 | """ 161 | Reads hs-music configuration and returns a list of 162 | directories in it 163 | """ 164 | 165 | extensions = [ 166 | ".mp3", 167 | ".m4a", 168 | ".ogg", 169 | ".flac", 170 | ] 171 | music_files = [] 172 | 173 | for option in config.options("hs-music"): 174 | directory = config.get("hs-music", option) 175 | if os.path.isdir(directory): 176 | music_files.extend(get_all_files(directory, extensions)) 177 | 178 | return music_files 179 | 180 | def _read_start(self, config): 181 | """ 182 | Reads hs-start configuration and returns a list of programs/files 183 | in it 184 | """ 185 | 186 | files = [] 187 | 188 | for option in config.options("hs-start"): 189 | if config.get("hs-start", option): 190 | files.append(config.get("hs-start", option)) 191 | 192 | return files 193 | 194 | def _read_wallpaper(self, config): 195 | """ 196 | Reads hs-wallpaper configuration and returns a list of directories 197 | in it 198 | """ 199 | 200 | extensions = [".png", ".jpg"] 201 | wallpapers = [] 202 | 203 | for option in config.options("hs-wallpaper"): 204 | directory = config.get("hs-wallpaper", option) 205 | if os.path.isdir(directory): 206 | wallpapers.extend(get_all_files(directory, extensions)) 207 | 208 | return wallpapers 209 | 210 | def _read_work(self, config): 211 | """ 212 | Reads the hs-work configuration and returns a list of files and 213 | the text editor to open them with 214 | """ 215 | 216 | files = [] 217 | editor = "" 218 | 219 | for option in config.options("hs-work"): 220 | value = config.get("hs-work", option) 221 | if option != "editor" and value: 222 | files.append(value) 223 | elif option == "editor": 224 | editor = value 225 | 226 | return files, editor 227 | -------------------------------------------------------------------------------- /src/LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | 60 | 61 | Finally, software patents pose a constant threat to the existence of 62 | any free program. We wish to make sure that a company cannot 63 | effectively restrict the users of a free program by obtaining a 64 | restrictive license from a patent holder. Therefore, we insist that 65 | any patent license obtained for a version of the library must be 66 | consistent with the full freedom of use specified in this license. 67 | 68 | Most GNU software, including some libraries, is covered by the 69 | ordinary GNU General Public License. This license, the GNU Lesser 70 | General Public License, applies to certain designated libraries, and 71 | is quite different from the ordinary General Public License. We use 72 | this license for certain libraries in order to permit linking those 73 | libraries into non-free programs. 74 | 75 | When a program is linked with a library, whether statically or using 76 | a shared library, the combination of the two is legally speaking a 77 | combined work, a derivative of the original library. The ordinary 78 | General Public License therefore permits such linking only if the 79 | entire combination fits its criteria of freedom. The Lesser General 80 | Public License permits more lax criteria for linking other code with 81 | the library. 82 | 83 | We call this license the "Lesser" General Public License because it 84 | does Less to protect the user's freedom than the ordinary General 85 | Public License. It also provides other free software developers Less 86 | of an advantage over competing non-free programs. These disadvantages 87 | are the reason we use the ordinary General Public License for many 88 | libraries. However, the Lesser license provides advantages in certain 89 | special circumstances. 90 | 91 | For example, on rare occasions, there may be a special need to 92 | encourage the widest possible use of a certain library, so that it becomes 93 | a de-facto standard. To achieve this, non-free programs must be 94 | allowed to use the library. A more frequent case is that a free 95 | library does the same job as widely used non-free libraries. In this 96 | case, there is little to gain by limiting the free library to free 97 | software only, so we use the Lesser General Public License. 98 | 99 | In other cases, permission to use a particular library in non-free 100 | programs enables a greater number of people to use a large body of 101 | free software. For example, permission to use the GNU C Library in 102 | non-free programs enables many more people to use the whole GNU 103 | operating system, as well as its variant, the GNU/Linux operating 104 | system. 105 | 106 | Although the Lesser General Public License is Less protective of the 107 | users' freedom, it does ensure that the user of a program that is 108 | linked with the Library has the freedom and the wherewithal to run 109 | that program using a modified version of the Library. 110 | 111 | The precise terms and conditions for copying, distribution and 112 | modification follow. Pay close attention to the difference between a 113 | "work based on the library" and a "work that uses the library". The 114 | former contains code derived from the library, whereas the latter must 115 | be combined with the library in order to run. 116 | 117 | 118 | 119 | GNU LESSER GENERAL PUBLIC LICENSE 120 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 121 | 122 | 0. This License Agreement applies to any software library or other 123 | program which contains a notice placed by the copyright holder or 124 | other authorized party saying it may be distributed under the terms of 125 | this Lesser General Public License (also called "this License"). 126 | Each licensee is addressed as "you". 127 | 128 | A "library" means a collection of software functions and/or data 129 | prepared so as to be conveniently linked with application programs 130 | (which use some of those functions and data) to form executables. 131 | 132 | The "Library", below, refers to any such software library or work 133 | which has been distributed under these terms. A "work based on the 134 | Library" means either the Library or any derivative work under 135 | copyright law: that is to say, a work containing the Library or a 136 | portion of it, either verbatim or with modifications and/or translated 137 | straightforwardly into another language. (Hereinafter, translation is 138 | included without limitation in the term "modification".) 139 | 140 | "Source code" for a work means the preferred form of the work for 141 | making modifications to it. For a library, complete source code means 142 | all the source code for all modules it contains, plus any associated 143 | interface definition files, plus the scripts used to control compilation 144 | and installation of the library. 145 | 146 | Activities other than copying, distribution and modification are not 147 | covered by this License; they are outside its scope. The act of 148 | running a program using the Library is not restricted, and output from 149 | such a program is covered only if its contents constitute a work based 150 | on the Library (independent of the use of the Library in a tool for 151 | writing it). Whether that is true depends on what the Library does 152 | and what the program that uses the Library does. 153 | 154 | 1. You may copy and distribute verbatim copies of the Library's 155 | complete source code as you receive it, in any medium, provided that 156 | you conspicuously and appropriately publish on each copy an 157 | appropriate copyright notice and disclaimer of warranty; keep intact 158 | all the notices that refer to this License and to the absence of any 159 | warranty; and distribute a copy of this License along with the 160 | Library. 161 | You may charge a fee for the physical act of transferring a copy, 162 | and you may at your option offer warranty protection in exchange for a 163 | fee. 164 | 165 | 2. You may modify your copy or copies of the Library or any portion 166 | of it, thus forming a work based on the Library, and copy and 167 | distribute such modifications or work under the terms of Section 1 168 | above, provided that you also meet all of these conditions: 169 | 170 | a) The modified work must itself be a software library. 171 | 172 | b) You must cause the files modified to carry prominent notices 173 | stating that you changed the files and the date of any change. 174 | 175 | c) You must cause the whole of the work to be licensed at no 176 | charge to all third parties under the terms of this License. 177 | 178 | d) If a facility in the modified Library refers to a function or a 179 | table of data to be supplied by an application program that uses 180 | the facility, other than as an argument passed when the facility 181 | is invoked, then you must make a good faith effort to ensure that, 182 | in the event an application does not supply such function or 183 | table, the facility still operates, and performs whatever part of 184 | its purpose remains meaningful. 185 | 186 | (For example, a function in a library to compute square roots has 187 | a purpose that is entirely well-defined independent of the 188 | application. Therefore, Subsection 2d requires that any 189 | application-supplied function or table used by this function must 190 | be optional: if the application does not supply it, the square 191 | root function must still compute square roots.) 192 | 193 | These requirements apply to the modified work as a whole. If 194 | identifiable sections of that work are not derived from the Library, 195 | and can be reasonably considered independent and separate works in 196 | themselves, then this License, and its terms, do not apply to those 197 | sections when you distribute them as separate works. But when you 198 | distribute the same sections as part of a whole which is a work based 199 | on the Library, the distribution of the whole must be on the terms of 200 | this License, whose permissions for other licensees extend to the 201 | entire whole, and thus to each and every part regardless of who wrote 202 | it. 203 | 204 | Thus, it is not the intent of this section to claim rights or contest 205 | your rights to work written entirely by you; rather, the intent is to 206 | exercise the right to control the distribution of derivative or 207 | collective works based on the Library. 208 | 209 | In addition, mere aggregation of another work not based on the Library 210 | with the Library (or with a work based on the Library) on a volume of 211 | a storage or distribution medium does not bring the other work under 212 | the scope of this License. 213 | 214 | 3. You may opt to apply the terms of the ordinary GNU General Public 215 | License instead of this License to a given copy of the Library. To do 216 | this, you must alter all the notices that refer to this License, so 217 | that they refer to the ordinary GNU General Public License, version 2, 218 | instead of to this License. (If a newer version than version 2 of the 219 | ordinary GNU General Public License has appeared, then you can specify 220 | that version instead if you wish.) Do not make any other change in 221 | these notices. 222 | 223 | Once this change is made in a given copy, it is irreversible for 224 | that copy, so the ordinary GNU General Public License applies to all 225 | subsequent copies and derivative works made from that copy. 226 | 227 | This option is useful when you wish to copy part of the code of 228 | the Library into a program that is not a library. 229 | 230 | 4. You may copy and distribute the Library (or a portion or 231 | derivative of it, under Section 2) in object code or executable form 232 | under the terms of Sections 1 and 2 above provided that you accompany 233 | it with the complete corresponding machine-readable source code, which 234 | must be distributed under the terms of Sections 1 and 2 above on a 235 | medium customarily used for software interchange. 236 | 237 | If distribution of object code is made by offering access to copy 238 | from a designated place, then offering equivalent access to copy the 239 | source code from the same place satisfies the requirement to 240 | distribute the source code, even though third parties are not 241 | compelled to copy the source along with the object code. 242 | 243 | 5. A program that contains no derivative of any portion of the 244 | Library, but is designed to work with the Library by being compiled or 245 | linked with it, is called a "work that uses the Library". Such a 246 | work, in isolation, is not a derivative work of the Library, and 247 | therefore falls outside the scope of this License. 248 | 249 | However, linking a "work that uses the Library" with the Library 250 | creates an executable that is a derivative of the Library (because it 251 | contains portions of the Library), rather than a "work that uses the 252 | library". The executable is therefore covered by this License. 253 | Section 6 states terms for distribution of such executables. 254 | 255 | When a "work that uses the Library" uses material from a header file 256 | that is part of the Library, the object code for the work may be a 257 | derivative work of the Library even though the source code is not. 258 | Whether this is true is especially significant if the work can be 259 | linked without the Library, or if the work is itself a library. The 260 | threshold for this to be true is not precisely defined by law. 261 | 262 | If such an object file uses only numerical parameters, data 263 | structure layouts and accessors, and small macros and small inline 264 | functions (ten lines or less in length), then the use of the object 265 | file is unrestricted, regardless of whether it is legally a derivative 266 | work. (Executables containing this object code plus portions of the 267 | Library will still fall under Section 6.) 268 | 269 | Otherwise, if the work is a derivative of the Library, you may 270 | distribute the object code for the work under the terms of Section 6. 271 | Any executables containing that work also fall under Section 6, 272 | whether or not they are linked directly with the Library itself. 273 | 274 | 6. As an exception to the Sections above, you may also combine or 275 | link a "work that uses the Library" with the Library to produce a 276 | work containing portions of the Library, and distribute that work 277 | under terms of your choice, provided that the terms permit 278 | modification of the work for the customer's own use and reverse 279 | engineering for debugging such modifications. 280 | 281 | You must give prominent notice with each copy of the work that the 282 | Library is used in it and that the Library and its use are covered by 283 | this License. You must supply a copy of this License. If the work 284 | during execution displays copyright notices, you must include the 285 | copyright notice for the Library among them, as well as a reference 286 | directing the user to the copy of this License. Also, you must do one 287 | of these things: 288 | 289 | a) Accompany the work with the complete corresponding 290 | machine-readable source code for the Library including whatever 291 | changes were used in the work (which must be distributed under 292 | Sections 1 and 2 above); and, if the work is an executable linked 293 | with the Library, with the complete machine-readable "work that 294 | uses the Library", as object code and/or source code, so that the 295 | user can modify the Library and then relink to produce a modified 296 | executable containing the modified Library. (It is understood 297 | that the user who changes the contents of definitions files in the 298 | Library will not necessarily be able to recompile the application 299 | to use the modified definitions.) 300 | 301 | b) Use a suitable shared library mechanism for linking with the 302 | Library. A suitable mechanism is one that (1) uses at run time a 303 | copy of the library already present on the user's computer system, 304 | rather than copying library functions into the executable, and (2) 305 | will operate properly with a modified version of the library, if 306 | the user installs one, as long as the modified version is 307 | interface-compatible with the version that the work was made with. 308 | 309 | c) Accompany the work with a written offer, valid for at 310 | least three years, to give the same user the materials 311 | specified in Subsection 6a, above, for a charge no more 312 | than the cost of performing this distribution. 313 | 314 | d) If distribution of the work is made by offering access to copy 315 | from a designated place, offer equivalent access to copy the above 316 | specified materials from the same place. 317 | 318 | e) Verify that the user has already received a copy of these 319 | materials or that you have already sent this user a copy. 320 | 321 | For an executable, the required form of the "work that uses the 322 | Library" must include any data and utility programs needed for 323 | reproducing the executable from it. However, as a special exception, 324 | the materials to be distributed need not include anything that is 325 | normally distributed (in either source or binary form) with the major 326 | components (compiler, kernel, and so on) of the operating system on 327 | which the executable runs, unless that component itself accompanies 328 | the executable. 329 | 330 | It may happen that this requirement contradicts the license 331 | restrictions of other proprietary libraries that do not normally 332 | accompany the operating system. Such a contradiction means you cannot 333 | use both them and the Library together in an executable that you 334 | distribute. 335 | 336 | 7. You may place library facilities that are a work based on the 337 | Library side-by-side in a single library together with other library 338 | facilities not covered by this License, and distribute such a combined 339 | library, provided that the separate distribution of the work based on 340 | the Library and of the other library facilities is otherwise 341 | permitted, and provided that you do these two things: 342 | 343 | a) Accompany the combined library with a copy of the same work 344 | based on the Library, uncombined with any other library 345 | facilities. This must be distributed under the terms of the 346 | Sections above. 347 | 348 | b) Give prominent notice with the combined library of the fact 349 | that part of it is a work based on the Library, and explaining 350 | where to find the accompanying uncombined form of the same work. 351 | 352 | 8. You may not copy, modify, sublicense, link with, or distribute 353 | the Library except as expressly provided under this License. Any 354 | attempt otherwise to copy, modify, sublicense, link with, or 355 | distribute the Library is void, and will automatically terminate your 356 | rights under this License. However, parties who have received copies, 357 | or rights, from you under this License will not have their licenses 358 | terminated so long as such parties remain in full compliance. 359 | 360 | 9. You are not required to accept this License, since you have not 361 | signed it. However, nothing else grants you permission to modify or 362 | distribute the Library or its derivative works. These actions are 363 | prohibited by law if you do not accept this License. Therefore, by 364 | modifying or distributing the Library (or any work based on the 365 | Library), you indicate your acceptance of this License to do so, and 366 | all its terms and conditions for copying, distributing or modifying 367 | the Library or works based on it. 368 | 369 | 10. Each time you redistribute the Library (or any work based on the 370 | Library), the recipient automatically receives a license from the 371 | original licensor to copy, distribute, link with or modify the Library 372 | subject to these terms and conditions. You may not impose any further 373 | restrictions on the recipients' exercise of the rights granted herein. 374 | You are not responsible for enforcing compliance by third parties with 375 | this License. 376 | 377 | 11. If, as a consequence of a court judgment or allegation of patent 378 | infringement or for any other reason (not limited to patent issues), 379 | conditions are imposed on you (whether by court order, agreement or 380 | otherwise) that contradict the conditions of this License, they do not 381 | excuse you from the conditions of this License. If you cannot 382 | distribute so as to satisfy simultaneously your obligations under this 383 | License and any other pertinent obligations, then as a consequence you 384 | may not distribute the Library at all. For example, if a patent 385 | license would not permit royalty-free redistribution of the Library by 386 | all those who receive copies directly or indirectly through you, then 387 | the only way you could satisfy both it and this License would be to 388 | refrain entirely from distribution of the Library. 389 | 390 | If any portion of this section is held invalid or unenforceable under any 391 | particular circumstance, the balance of the section is intended to apply, 392 | and the section as a whole is intended to apply in other circumstances. 393 | 394 | It is not the purpose of this section to induce you to infringe any 395 | patents or other property right claims or to contest validity of any 396 | such claims; this section has the sole purpose of protecting the 397 | integrity of the free software distribution system which is 398 | implemented by public license practices. Many people have made 399 | generous contributions to the wide range of software distributed 400 | through that system in reliance on consistent application of that 401 | system; it is up to the author/donor to decide if he or she is willing 402 | to distribute software through any other system and a licensee cannot 403 | impose that choice. 404 | 405 | This section is intended to make thoroughly clear what is believed to 406 | be a consequence of the rest of this License. 407 | 408 | 12. If the distribution and/or use of the Library is restricted in 409 | certain countries either by patents or by copyrighted interfaces, the 410 | original copyright holder who places the Library under this License may add 411 | an explicit geographical distribution limitation excluding those countries, 412 | so that distribution is permitted only in or among countries not thus 413 | excluded. In such case, this License incorporates the limitation as if 414 | written in the body of this License. 415 | 416 | 13. The Free Software Foundation may publish revised and/or new 417 | versions of the Lesser General Public License from time to time. 418 | Such new versions will be similar in spirit to the present version, 419 | but may differ in detail to address new problems or concerns. 420 | 421 | Each version is given a distinguishing version number. If the Library 422 | specifies a version number of this License which applies to it and 423 | "any later version", you have the option of following the terms and 424 | conditions either of that version or of any later version published by 425 | the Free Software Foundation. If the Library does not specify a 426 | license version number, you may choose any version ever published by 427 | the Free Software Foundation. 428 | 429 | 14. If you wish to incorporate parts of the Library into other free 430 | programs whose distribution conditions are incompatible with these, 431 | write to the author to ask for permission. For software which is 432 | copyrighted by the Free Software Foundation, write to the Free 433 | Software Foundation; we sometimes make exceptions for this. Our 434 | decision will be guided by the two goals of preserving the free status 435 | of all derivatives of our free software and of promoting the sharing 436 | and reuse of software generally. 437 | 438 | NO WARRANTY 439 | 440 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 441 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 442 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 443 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 444 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 445 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 446 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 447 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 448 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 449 | 450 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 451 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 452 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 453 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 454 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 455 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 456 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 457 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 458 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 459 | DAMAGES. 460 | 461 | END OF TERMS AND CONDITIONS 462 | 463 | How to Apply These Terms to Your New Libraries 464 | 465 | If you develop a new library, and you want it to be of the greatest 466 | possible use to the public, we recommend making it free software that 467 | everyone can redistribute and change. You can do so by permitting 468 | redistribution under these terms (or, alternatively, under the terms of the 469 | ordinary General Public License). 470 | 471 | To apply these terms, attach the following notices to the library. It is 472 | safest to attach them to the start of each source file to most effectively 473 | convey the exclusion of warranty; and each file should have at least the 474 | "copyright" line and a pointer to where the full notice is found. 475 | 476 | 477 | Copyright (C) 478 | 479 | This library is free software; you can redistribute it and/or 480 | modify it under the terms of the GNU Lesser General Public 481 | License as published by the Free Software Foundation; either 482 | version 2.1 of the License, or (at your option) any later version. 483 | 484 | This library is distributed in the hope that it will be useful, 485 | but WITHOUT ANY WARRANTY; without even the implied warranty of 486 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 487 | Lesser General Public License for more details. 488 | 489 | You should have received a copy of the GNU Lesser General Public 490 | License along with this library; if not, write to the Free Software 491 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 492 | 493 | Also add information on how to contact you by electronic and paper mail. 494 | 495 | You should also get your employer (if you work as a programmer) or your 496 | school, if any, to sign a "copyright disclaimer" for the library, if 497 | necessary. Here is a sample; alter the names: 498 | 499 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 500 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 501 | 502 | , 1 April 1990 503 | Ty Coon, President of Vice 504 | 505 | That's all there is to it! 506 | 507 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------