Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero File Length Error Fix Attempt #20

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ import ugit

ugit.backup() # good idea to backup your files!

ugit.pull_all()

if ugit.repo_has_updates():
ugit.pull_all()
else:
print('no new updates available')
```
### Installation

Expand Down
67 changes: 39 additions & 28 deletions ugit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,16 @@

global internal_tree

#### -------------User Variables----------------####
####
# Default Network to connect using wificonnect()
ssid = "OpenMuscle"
password = "3141592653"
#### ---User Variables in ugit_config.py---####
import ugit_config

# CHANGE TO YOUR REPOSITORY INFO
# Repository must be public if no personal access token is supplied
user = 'turfptax'
repository = 'ugit_test'
token = ''
# Change this variable to 'master' or any other name matching your default branch
default_branch = 'main'

# Don't remove ugit.py from the ignore_files unless you know what you are doing :D
# Put the files you don't want deleted or updated here use '/filename.ext'
ignore_files = ['/ugit.py']
ignore = ignore_files
### -----------END OF USER VARIABLES ----------####
ssid = ugit_config.ssid
password = ugit_config.password
user = ugit_config.user
repository = ugit_config.repository
token = ugit_config.token
default_branch = ugit_config.default_branch
ignore = ugit_config.ignore_files

# Static URLS
# GitHub uses 'main' instead of master for python repository trees
Expand Down Expand Up @@ -68,7 +59,6 @@ def pull_all(tree=call_trees_url,raw = raw,ignore = ignore,isconnected=False):
tree = pull_git_tree()
internal_tree = build_internal_tree()
internal_tree = remove_ignore(internal_tree)
print(' ignore removed ----------------------')
print(internal_tree)
log = []
# download and save all files
Expand Down Expand Up @@ -100,10 +90,24 @@ def pull_all(tree=call_trees_url,raw = raw,ignore = ignore,isconnected=False):
logfile = open('ugit_log.py','w')
logfile.write(str(log))
logfile.close()
time.sleep(10)
write_git_tree_file()
print('resetting machine in 10: machine.reset()')
time.sleep(10)
machine.reset()
#return check instead return with global

def repo_has_updates():
print('Returns True if an update from repo is available')
if not 'ugit.tree' in [file[0] for file in os.ilistdir()]:
github_tree = pull_git_tree()
with open('ugit.tree','r') as f:
saved_tree = f.read()
if str(github_tree) == saved_tree:
return False
else:
return True
else:
return True

def wificonnect(ssid=ssid,password=password):
print('Use: like ugit.wificonnect(SSID,Password)')
Expand Down Expand Up @@ -149,12 +153,12 @@ def add_to_tree(dir_item):


def get_hash(file):
print(file)
o_file = open(file)
r_file = o_file.read()
sha1obj = hashlib.sha1(r_file)
hash = sha1obj.digest()
return(binascii.hexlify(hash))
print(file)
o_file = open(file)
r_file = o_file.read()
sha1obj = hashlib.sha1(r_file)
hash = sha1obj.digest()
return(binascii.hexlify(hash))

def get_data_hash(data):
sha1obj = hashlib.sha1(data)
Expand Down Expand Up @@ -193,7 +197,12 @@ def parse_git_tree():
print('dirs:',dirs)
print('files:',files)


def write_git_tree_file():
trees = pull_git_tree()
tree_file = open('ugit.tree','w')
tree_file.write(str(trees))
tree_file.close()

def check_ignore(tree=call_trees_url,raw = raw,ignore = ignore):
os.chdir('/')
tree = pull_git_tree()
Expand Down Expand Up @@ -233,8 +242,10 @@ def backup():
for i in int_tree:
data = open(i[0],'r')
backup_text += f'FN:SHA1{i[0]},{i[1]}\n'
backup_text += '---'+data.read()+'---\n'
if data.read():
backup_text += '---'+data.read()+'---\n'
data.close()
backup = open('ugit.backup','w')
backup.write(backup_text)
backup.close()

19 changes: 19 additions & 0 deletions ugit_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ugit_config.py
#### -------------User Variables----------------####
# Default Network to connect using wificonnect()
ssid = "OpenMuscle"
password = "3141592653"

# CHANGE TO YOUR REPOSITORY INFO
# Repository must be public if no personal access token is supplied
user = 'turfptax'
repository = 'ugit_test'
token = ''
# Change this variable to 'master' or any other name matching your default branch
default_branch = 'main'

# Don't remove ugit.py from the ignore_files unless you know what you are doing :D
# Put the files you don't want deleted or updated here use '/filename.ext'
ignore_files = ['/ugit.py','/ugit.backup','/ugit.tree']
ignore = ignore_files
### -----------END OF USER VARIABLES ----------####