Skip to content

Commit

Permalink
Merge pull request #1 from MarkMichon1/staging
Browse files Browse the repository at this point in the history
merge staging to master
  • Loading branch information
MarkMichon1 authored May 24, 2019
2 parents 829b883 + 880792c commit c7d842d
Show file tree
Hide file tree
Showing 39 changed files with 1,277 additions and 630 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Mark Michon
Copyright (c) 2019 - ∞ Mark Michon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
335 changes: 248 additions & 87 deletions README.md

Large diffs are not rendered by default.

31 changes: 18 additions & 13 deletions __init__.py → bitglitter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)
#
# Copyright (c) 2019 Mark Michon
# Copyright (c) 2019 - ∞ Mark Michon
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,31 +20,36 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ===============================================================================
#
# Official project page:
# https://github.com/MarkMichon1/BitGlitter
#
# Guides and roadmap:
# Guides and roadmap (under construction!):
# https://github.com/MarkMichon1/BitGlitter/wiki
#
# Discord channel:
# TBA
# https://discord.gg/t9uv2pZ
#
# Have fun! :)
#
# - Mark
# ===============================================================================


# BASIC USES
from bitglitter.read.read import read
# CORE USES
from bitglitter.write.write import write


# CUSTOM PALETTE
from bitglitter.palettes.palettefunctions import addCustomPalette, editNicknameToCustomPalette, clearAllCustomPalettes,\
clearCustomPaletteNicknames, printFullPaletteList, removeCustomPalette, removeCustomPaletteNickname
from bitglitter.read.read import read


# GENERAL CONFIGURATION
from bitglitter.config.configfunctions import clearSession, clearStats, outputStats


# MISCELLANEOUS UTILITIES
from bitglitter.protocols.protocol_one.write.protocol_one_verifywriteparameters import paletteVerify
# PARTIAL SAVE CONTROL
from bitglitter.read.savedfilefunctions import beginAssembly, printFullSaveList, removePartialSave, updatePartialSave, \
removeAllPartialSaves


# CUSTOM PALETTE
from bitglitter.palettes.palettefunctions import addCustomPalette, editNicknameToCustomPalette, clearAllCustomPalettes,\
clearCustomPaletteNicknames, printFullPaletteList, removeCustomPalette, removeCustomPaletteNickname
2 changes: 1 addition & 1 deletion bitglitter/config/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import pickle

from bitglitter.config.configobjects import Config
Expand All @@ -7,5 +6,6 @@
try:
with open ('config.pickle', 'rb') as pickleLoad:
config = pickle.load(pickleLoad)

except:
config = Config()
23 changes: 6 additions & 17 deletions bitglitter/config/configfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,28 @@

from bitglitter.config.config import config

# These functions are for end users.

def outputStats(path):
'''Writes a text file to a file path outlining usage statistics.'''

activePath = os.path.join(os.getcwd(), path)
with open(activePath + '\\Statistics.txt', 'w') as writer:
writer.write(str(config.statsHandler))


def clearStats():
'''Resets statistics back to zero in all fields.'''

config.statsHandler.clearStats()
config.saveSession()


def clearSession():
'''Tries to remove the session pickle if it exists, clearing all statistics and custom colors.'''

try:
config.assembler.clearPartialSaves()
os.remove('config.pickle')
except:
pass


def removePartialSave(hash):
'''Removes the PartialSave object from partialReadHolder in config as well as removes the folder containing any
fragments.'''
config.saveSession()


def clearPartialSaves():
'''Removes all PartialSave objects and removes all data saved.'''
config.saveSession()


def outputPartialSaveList(path):
'''Writes a text file to a file path outlining partial save data.'''
pass
pass
9 changes: 5 additions & 4 deletions bitglitter/config/configobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class Config:
'''This is the master object that holds all session data.'''

def __init__(self):
#todo remove existing folder for save stuff if it exists. try

self.colorHandler = PaletteHandler()
self.statsHandler = Statistics()
self.assembler = Assembler()
self.assembler.clearPartialSaves() # Deleting old folder if new config object must be made.

self.saveSession()

Expand Down Expand Up @@ -41,6 +41,7 @@ def __str__(self):
'''This is used by outputStats() in configfunctions to output a nice formatted text file showing usage
statistics.
'''

return('*' * 21 + '\nStatistics\n' + '*' * 21 + f'\n\nTotal Blocks Wrote: {self.blocksWrote}'
f'\nTotal Frames Wrote: {self.framesWrote}'
f'\nTotal Data Wrote: {int(self.dataWrote / 8)} B'
Expand Down Expand Up @@ -72,6 +73,7 @@ class PaletteHandler:
All functions available in palettefunctions module that deal with custom palettes are interfacing with dictionaries
customPaletteList and customPaletteNicknameList in this object.
'''

def __init__(self):
self.defaultPaletteList = {'1' : DefaultPalette("1 bit default",
"Two colors, black and white. While it has the lowest density of one bit of data per "
Expand All @@ -85,7 +87,7 @@ def __init__(self):

'22': DefaultPalette("2 bit alternate", "Four colors; black, magenta, cyan, yellow.",
((0, 0, 0), (255, 255, 0), (0, 255, 255), (255, 0, 255)), 255,
2),
22),

'3' : DefaultPalette("3 bit default",
"Eight colors.", ((0,0,0), (255,0,0), (0,255,0), (0,0,255), (255,255,0), (0,255,255),
Expand All @@ -112,5 +114,4 @@ def __init__(self):
}

self.customPaletteList = {}
self.customPaletteNicknameList = {}

self.customPaletteNicknameList = {}
20 changes: 12 additions & 8 deletions bitglitter/config/constants.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# This gets changed every new version. It is included in the ASCII part of the stream header for diagnostic and
# debugging purposes.
BG_VERSION = "1.0"

VALID_VIDEO_FORMATS = ['.avi', '.flv', '.mov', '.mp4', '.wmv']
VALID_IMAGE_FORMATS = ['.bmp', '.jpg', '.png']
# Dev note- this gets updated at version change. This is included in ASCII stream header for debugging purposes.
BG_VERSION = "1.0"

# Default folder paths
WRITE_PATH = 'Temp'
READ_PATH = 'Partial Saves'

# Crypto
SCRYPT_N_DEFAULT = 14
SCRYPT_R_DEFAULT = 8
SCRYPT_P_DEFAULT = 1

# Read specific
BAD_FRAME_STRIKES = 10
VALID_VIDEO_FORMATS = ['.avi', '.flv', '.mov', '.mp4', '.wmv']
VALID_IMAGE_FORMATS = ['.bmp', '.jpg', '.png']

# Write specific
HEADER_PALETTE_ID ='4'
STREAM_PALETTE_ID ='4'
PIXEL_WIDTH = 20
BLOCK_HEIGHT = 54
BLOCK_WIDTH = 96
HEADER_PALETTE_ID ='6'
STREAM_PALETTE_ID ='6'
PIXEL_WIDTH = 24
BLOCK_HEIGHT = 45
BLOCK_WIDTH = 80
FRAMES_PER_SECOND = 30
4 changes: 3 additions & 1 deletion bitglitter/config/loggingset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging
import os

def _loggingSetter(loggingLevel, loggingPrint, loggingSaveOutput):

def loggingSetter(loggingLevel, loggingPrint, loggingSaveOutput):
'''This is what the logging level and output during the write operation. It's worth nothing that this is the ONLY
function that checks parameters outside of verifyWriteParameters, because that function's logging outputs hinge in
the configuration for logging.
Expand Down Expand Up @@ -36,6 +37,7 @@ def _loggingSetter(loggingLevel, loggingPrint, loggingSaveOutput):
outputLog.setLevel(loggingLevelDict[loggingLevel])

if loggingPrint:

printLog = logging.getLogger()
printLogHandler = logging.StreamHandler()
printLogFormatter = logging.Formatter("%(asctime)s.%(msecs)03d %(levelname)s %(message)s", "%H:%M:%S")
Expand Down
1 change: 1 addition & 0 deletions bitglitter/filepackager/filepackager.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def unpackage(fileName, savePath, streamSHA):
pass
outputPath += '/' + streamSHA
logging.debug("Making Folder: " + streamSHA + " and moving into it.")
rootFolderCreated = True

os.chdir(outputPath)
temp = b''
Expand Down
25 changes: 15 additions & 10 deletions bitglitter/palettes/palettefunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import time

from bitglitter.config.config import config
from bitglitter.utilities.generalverifyfunctions import properStringSyntax
from bitglitter.palettes.paletteutilities import _addCustomPaletteDirect, colorDistance, returnPaletteID
from bitglitter.utilities.generalverifyfunctions import properStringSyntax

# All of these functions are for end users except for _dictPopper.


def dictPopper(idOrNick):
def _dictPopper(idOrNick):
'''This is an internal function used for removeCustomPalette(), addNicknameToCustomPalette(), and
removeCustomPaletteNicknames(). Since a user can either either the palette ID OR it's nickname as an argument,
first we must check whether that key exists. If it does, it will check both dictionaries in the ColorHandler object
Expand All @@ -19,11 +19,13 @@ def dictPopper(idOrNick):
tempHolder = config.colorHandler.customPaletteNicknameList[idOrNick]
del config.colorHandler.customPaletteList[tempHolder.id]
return config.colorHandler.customPaletteNicknameList.pop(idOrNick)

elif idOrNick in config.colorHandler.customPaletteList:
tempHolder = config.colorHandler.customPaletteList[idOrNick]
if config.colorHandler.customPaletteNicknameList[tempHolder.nickname]:
del config.colorHandler.customPaletteNicknameList[tempHolder.nickname]
return config.colorHandler.customPaletteList.pop(idOrNick)

else:
raise ValueError(f"'{idOrNick}' does not exist.")

Expand Down Expand Up @@ -66,7 +68,7 @@ def addCustomPalette(paletteName, paletteDescription, colorSet, optionalNickname
minDistance = colorDistance(colorSet)
if minDistance == 0:
raise ValueError("Calculated color distance is 0. This occurs when you have two identical colors in your"
" palette. This breaks the communication protocol. See BitGlitter guide for more information.")
"\npalette. This breaks the communication protocol. See BitGlitter guide for more information.")

'''At this point, assuming no errors were raised, we're ready to instantiate the custom color object. This function
creates an identification for the object. For as long as the palette exists, this is a permanent ID that can be
Expand All @@ -75,13 +77,13 @@ def addCustomPalette(paletteName, paletteDescription, colorSet, optionalNickname

id = returnPaletteID(nameString, descriptionString, dateCreated, colorSet)
_addCustomPaletteDirect(nameString, descriptionString, colorSet, minDistance, dateCreated, id, nicknameString)

return id


def removeCustomPalette(idOrNick):
'''Removes custom palette completely from the config file.'''
dictPopper(idOrNick)

_dictPopper(idOrNick)
config.saveSession()


Expand All @@ -92,14 +94,13 @@ def editNicknameToCustomPalette(idOrNick, newName):
and newName not in config.colorHandler.customPaletteNicknameList \
and newName not in config.colorHandler.defaultPaletteList:

tempHolder = dictPopper(idOrNick)
tempHolder = _dictPopper(idOrNick)
tempHolder.nickname = newName
config.colorHandler.customPaletteList[tempHolder.id] = tempHolder
config.colorHandler.customPaletteNicknameList[tempHolder.nickname] = tempHolder
config.saveSession()

else:

raise ValueError(f"'{newName}' is already being used, please try another.")


Expand All @@ -108,7 +109,7 @@ def removeCustomPaletteNickname(idOrNick):
nickname.
'''

tempHolder = dictPopper(idOrNick)
tempHolder = _dictPopper(idOrNick)
tempHolder.nickname = ""
config.colorHandler.customPaletteList[tempHolder.id] = tempHolder
config.saveSession()
Expand All @@ -130,9 +131,11 @@ def clearCustomPaletteNicknames():

def printFullPaletteList(path):
'''Writes a text file to a file path outlining available color palettes.'''

activePath = os.path.join(os.getcwd(), path)

with open(activePath + '\\Palette List.txt', 'w') as writer:
with open(activePath + '\\BitGlitter Palette List.txt', 'w') as writer:

writer.write('*' * 21 + '\nDefault Palettes\n' + '*' * 21 + '\n')

for someKey in config.colorHandler.defaultPaletteList:
Expand All @@ -144,12 +147,14 @@ def printFullPaletteList(path):

for someKey in config.colorHandler.customPaletteList:
writer.write('\n' + str(config.colorHandler.customPaletteList[someKey]) + '\n')

else:
writer.write('\nNo custom palettes (yet)')


def clearAllCustomPalettes():
'''Removes all custom palettes from both the ID dictionary and nickname dictionary.'''

config.colorHandler.customPaletteNicknameList = {}
config.colorHandler.customPaletteList = {}
config.saveSession()
8 changes: 7 additions & 1 deletion bitglitter/palettes/paletteobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def __init__(self, name, description, colorSet, colorDistance):
self.bitLength = int(math.log(self.numberOfColors, 2))

def __getitem__(self, item):

return self.colorSet[item]


class DefaultPalette(AbstractPalette):
'''These are palettes that come default with BitGlitter.'''
'''These are palettes that come default with BitGlitter. They cannot be changed or removed.'''

def __init__(self, name, description, colorSet, colorDistance, id):

Expand All @@ -33,6 +34,7 @@ def __init__(self, name, description, colorSet, colorDistance, id):


def __str__(self):

return (f'Name: {self.name}\nIdentification Code: {str(self.id)}\nDescription: {self.description}\nBit Length: '
f'{str(self.bitLength)}\nNumber of Colors: {str(self.numberOfColors)}\nColor Set: {str(self.colorSet)}'
f'\nColor Distance: {str(self.colorDistance)}\n')
Expand All @@ -54,6 +56,7 @@ def __init__(self, name, description, colorSet, colorDistance, dateCreated, id,


def __str__(self):

return (f"Name: {self.name}\nIdentification Code: {str(self.id)}\nNickname: {self.nickname}\nDescription: "
f"{self.description}"
f"\nDate Created: {datetime.datetime.fromtimestamp(self.dateCreated).strftime('%A, %B %d, %Y - %I:%M:%S %p')}"
Expand All @@ -67,7 +70,9 @@ class TwentyFourBitPalette:
are no colors in colorSet. There is only one object that can exist of this class, because of the specific values
needed. This object is what represents the 24 bit color set.
'''

def __init__(self):

self.name = "24 bit default"
self.description = "EXPERIMENTAL! ~16.7 million colors. This will only work in lossless" \
" environments, any sort of compression will corrupt the data."
Expand All @@ -80,6 +85,7 @@ def __init__(self):


def __str__(self):

return (f'Name: {self.name}\nIdentification Code: {str(self.id)}\nDescription: {self.description}\nBit Length: '
f'{str(self.bitLength)}\nNumber of Colors: {str(self.numberOfColors)}\nColor Set: Too many '
f'to list (see directly above)\nColor Distance: {str(self.colorDistance)}\n')
Loading

0 comments on commit c7d842d

Please sign in to comment.