Skip to content

Commit e7e4452

Browse files
committed
Restructure scripts folder. Added detailed help to command line help. Extended README file to describe the available scripts.
1 parent 2efb830 commit e7e4452

File tree

11 files changed

+58
-59
lines changed

11 files changed

+58
-59
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.project
2+
.pydevproject

README

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=Funf Data Processing=
2+
3+
This project contains convenience scripts for processing Funf data files.
4+
These files are designed to be used as standalone scripts, and not as a library to be imported.
5+
Make sure to download and install the dependencies before running the scripts.
6+
7+
8+
==Data Processing==
9+
Scripts for processing data once it has been retrieved from devices.
10+
11+
Dependencies:
12+
* PyCrypto ( https://www.dlitz.net/software/pycrypto/ )
13+
14+
15+
===decrypt.py===
16+
Decrypts files using the DES key specified, or the one included in this script. Keeps a backup copy of the original file.
17+
*WARNING:* This script does not detect if a file has already been decrypted. Decrypting a file that is not encrypted will scramble the file.
18+
19+
===dbdecrypt.py===
20+
Safe script for decrypting sqlite3 db files. Checks to see if the file can be opened by Sqlite. Only if it cannot open the file, it decrypts it.
21+
22+
===dbmerge.py===
23+
Merge many database files into one file.
24+
25+
26+
27+
==Simple Server==
28+
A basic reference HTTP server for communicating with Funf applications.
29+
The server hosts one configuration file (/config), and accepts multipart form uploads of files (/data).
30+
31+
This is meant to be a reference implementation for prototyping, and not meant to be a stable long running implementation.
32+
33+
34+
35+
36+

data_processing/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.project
2+
.pydevproject
3+
14
merged*
25
uploads*
36
*.pyc

data_processing/.project

-17
This file was deleted.

data_processing/README

-9
This file was deleted.

data_processing/dbdecrypt.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def decrypt_if_not_db_file(file_name, extension=None):
3434
shutil.move(file_name + "." + extension, file_name)
3535

3636
if __name__ == '__main__':
37-
parser = OptionParser(usage="usage: %prog [options] [sqlite_file1.db [sqlite_file2.db...]]")
37+
usage = "%prog [options] [sqlite_file1.db [sqlite_file2.db...]]"
38+
description = "Safely decrypt Sqlite3 db files. Checks to see if the file can be opened by Sqlite. If so, the file is left alone, otherwise the file is decrypted. Uses the decrypt script, so it always keeps a backup of the original encrypted files. "
39+
parser = OptionParser(usage="%s\n\n%s" % (usage, description))
3840
parser.add_option("-i", "--inplace", dest="extension", default=None,
3941
help="The extension to rename the original file to. Will not overwrite file if it already exists. Defaults to '%s'." % decrypt.default_extension,)
4042
(options, args) = parser.parse_args()

data_processing/dbmerge.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ def merge(db_files=None, out_file=None):
5959

6060

6161
if __name__ == '__main__':
62-
parser = OptionParser(usage="usage: %prog [options] [sqlite_file1.db [sqlite_file2.db...]]")
62+
usage = "%prog [options] [sqlite_file1.db [sqlite_file2.db...]]"
63+
description = "Merges many database files into one file."
64+
parser = OptionParser(usage="%s\n\n%s" % (usage, description))
6365
parser.add_option("-o", "--output", dest="file", default=None,
64-
help="Filename to merge all files into. Created if it doesn't exist.", metavar="FILE")
66+
help="Filename to merge all files into. Will not overwrite a file if it already exists.", metavar="FILE")
6567
(options, args) = parser.parse_args()
6668
try:
6769
merge(args, options.file)

data_processing/decrypt.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
_des_key = string.join([chr(byte) for byte in (12,34,45,54,27,122,33,45)], '')
1111
default_extension = "orig"
1212

13-
def decrypt(file_names, extension=None):
13+
def decrypt(file_names, extension=None, key=None):
1414
extension = extension or default_extension
15-
decryptor = DES.new(_des_key)
15+
key = key or _des_key
16+
decryptor = DES.new(key)
1617
for file_name in file_names:
1718
with open(file_name) as file:
1819
encrypted_data = file.read()
@@ -25,8 +26,12 @@ def decrypt(file_names, extension=None):
2526

2627

2728
if __name__ == '__main__':
28-
parser = OptionParser(usage="usage: %prog [options] [file1 [file2...]]")
29+
usage = "%prog [options] [file1 [file2...]]"
30+
description = "Decrypts files using the DES key specified, or the one included in this script. Keeps a backup copy of the original file. \nWARNING: This script does not detect if a file has already been decrypted. \nDecrypting a file that is not encrypted will scramble the file."
31+
parser = OptionParser(usage="%s\n\n%s" % (usage, description))
2932
parser.add_option("-i", "--inplace", dest="extension", default=None,
3033
help="The extension to rename the original file to. Will not overwrite file if it already exists. Defaults to '%s'." % default_extension,)
34+
parser.add_option("-k", "--key", dest="key", default=None,
35+
help="The DES key used to decrypt the files. Uses the default hard coded one if one is not supplied.",)
3136
(options, args) = parser.parse_args()
3237
decrypt(args, options.extension)

simple_server/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.project
2+
.pydevproject

simple_server/.project

-17
This file was deleted.

simple_server/.pydevproject

-10
This file was deleted.

0 commit comments

Comments
 (0)