Skip to content

Commit

Permalink
Merge pull request #9 from duch3201/Testing
Browse files Browse the repository at this point in the history
Testing branch merge
  • Loading branch information
Mathewnd committed Jan 13, 2021
2 parents 28de6a4 + cb4e4ef commit 12c5af6
Show file tree
Hide file tree
Showing 6 changed files with 450 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ a file compression app written in python
Note. To properly run this file open the header.py
Note2. This app requires that python is installed

https://trello.com/b/HaC2BQJz/lightfile link to a trello board
th app is in beta 1.0

https://trello.com/b/HaC2BQJz/lightfile link to a trello board


We are in alpha 2.1, if you want to download the 2.1 alpha please go to the Testing branch.
Binary file added __pycache__/header.cpython-39.pyc
Binary file not shown.
167 changes: 152 additions & 15 deletions comrfile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,106 @@
import zlib
import sys
import time
import base64
import os

from datetime import datetime
import ctypes
from inspect import getsourcefile
from os.path import abspath
ctypes.windll.kernel32.SetConsoleTitleW("LightFile") #this is for the window title
#takes a complete path (example: C:/Users/JohnDoe/Desktop/example.txt) and removes the file name (in this case, C:/Users/JohnDoe/Desktop)

def getPath(s):

#reverse string

reversedstr = ""

for c in reversed(s):
reversedstr = reversedstr + c

#remove the rest of the path, leaving only the file name

tempfn = ""
shouldAdd = False

for c in reversedstr:
if(shouldAdd == True):
tempfn = tempfn + c
if(c == '\\' or c == '/'):
shouldAdd = True



#reverse the file name to make it valid again

filename = ""

for c in reversed(tempfn):
filename = filename + c


return filename

#takes a complete path (example: C:/Users/JohnDoe/Desktop/example.txt) and returns just the file name (in this case, example.txt)

# s = string containing the path

def getFileNameFromPath(s):

#reverse string

reversedstr = ""

for c in reversed(s):
reversedstr = reversedstr + c

#remove the rest of the path, leaving only the file name

tempfn = ""

for c in reversedstr:
if(c == '\\' or c == '/'):
break
tempfn = tempfn + c


#reverse the file name to make it valid again

filename = ""

for c in reversed(tempfn):
filename = filename + c


return filename



root_path = '/'
File_ext = ".lfc"



#if no extra arguments give the standard selection
if(len(sys.argv) == 1):
print("Selected to compress.\nEnter the input file")
path_total = input(": ")
print("Enter the path to the output folder")
output_path = input (": ")
else:
path_total = sys.argv[1]
output_path = getPath(sys.argv[2])

file_name = input("please enter a file name:\n")
path = input("enter a path to the file: ")
path = getPath(path_total)
file_name = getFileNameFromPath(path_total)


#change to the system root path

os.chdir(root_path)

#try changing to the path of the file

try:
os.chdir(path)
except FileNotFoundError:
Expand All @@ -19,32 +110,78 @@
except PermissionError:
print("You do not have permissions to change to {0}".format(path))

#read the file

#os.chdir(path)

str = open('file_name', 'br')
try:
str = open(file_name, 'rb').read()
except FileNotFoundError:
print("This file does not exist!")

#print(str)
start_time = time.time()

print("raw size:", sys.getsizeof(str))

compressed_data = zlib.compress(str, 2)
compressed_data = zlib.compress(str, 9)

print("comppresed size:", sys.getsizeof(compressed_data))
#change to the output location

os.chdir(root_path)
os.chdir(output_path)

print("comppresed size:", sys.getsizeof(compressed_data))

#ask for name if not automated

if(len(sys.argv) == 1):
print("Insert the new compressed file name") #if it's blank simply default it to compressed.lfc
new_compr_fn = input(": ")
else:
new_compr_fn = getFileNameFromPath(sys.argv[2])

if (new_compr_fn == ""):
new_compr_fn = "compressed" #nothing was chosen so change the selected name to compressed, as we default do it

createfile = open('compressed.txt', 'w')
#create the file and write the data to it

createfile = open(new_compr_fn + File_ext, 'w')
createfile.close()
savecomp = open('compressed.txt', 'wb')
compressed_data.encode("utf8", "ascii")
savecomp = open(new_compr_fn + File_ext, 'wb')
savecomp.write(compressed_data)
savecomp.close()

os.sleep(10)
app_root_path = getPath(abspath(getsourcefile(lambda:0)))

#history file
histfileopn = "history.lfh"

os.chdir(app_root_path)
current_datetime = datetime.now()
current_time = datetime.now().time()

# creating / opening the historu.lfh file

history = open(histfileopn, 'w')
history.write(path_total)
history.close()

#delete the file if the user wants.

if(len(sys.argv) == 1):
print("do you want to delete the original file")
delfile = input(": ")
else:
delfile = "n"

if (delfile == "yes" or delfile == 'y' or delfile == "Y"):
os.chdir(output_path)
os.remove(file_name)

# print elapsed time
elapsed_time = time.time() - start_time
print("the compression took only: ", round(elapsed_time),"sec" )

#wait 10 seconds and close if not run by commandline

#os.system('python header.py')
if(len(sys.argv) == 1):
print("compression successful app will close in 10 sec")
time.sleep(10)
Loading

0 comments on commit 12c5af6

Please sign in to comment.