Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
__pycache__
12 changes: 5 additions & 7 deletions checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

__author__ = 'snorri.sturluson'

CHUNK_SZ = 8192

def calc_checksum(filename):
"""
Expand All @@ -10,12 +11,9 @@ def calc_checksum(filename):
:return:
"""
try:
f = open(filename, "rb")
contents = f.read()
m = hashlib.md5()
m.update(contents)
checksum = m.hexdigest()
return checksum

with open(filename, 'rb') as f:
m = hashlib.md5()
[m.update(chunk) for chunk in iter(lambda: f.read(CHUNK_SZ), b'')]
return m.hexdigest()
except IOError:
return None
20 changes: 9 additions & 11 deletions diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def scan_missing_files(index, res_folder):
print "Scanning index, checking for missing files"
print("Scanning index, checking for missing files")
num_files = len(index)
missing = 0
missing_bytes = 0
Expand All @@ -26,7 +26,7 @@ def scan_missing_files(index, res_folder):


def scan_extra_files(index_by_cached_names, res_folder):
print "Scanning %s, checking for extra files" % res_folder
print("Scanning %s, checking for extra files" % res_folder)
extras = 0
extra_bytes = 0
scanned = 0
Expand All @@ -45,21 +45,19 @@ def scan_extra_files(index_by_cached_names, res_folder):


def diff_cache(index, res_folder):
index_by_cached_names = {}
for entry in index:
index_by_cached_names[entry.cached_name] = entry
index_by_cached_names = {ntry.cached_name: ntry for ntry in index}

extras, extra_bytes = scan_extra_files(index_by_cached_names, res_folder)
missing, missing_bytes, missing_download_bytes = scan_missing_files(index, res_folder)

if missing:
print "%d files missing:" % missing
print "%s to download (%s on disk)" % (format_memory(missing_download_bytes), format_memory(missing_bytes))
print
print("%d files missing:" % missing)
print("%s to download (%s on disk)" % (format_memory(missing_download_bytes), format_memory(missing_bytes)))
print('')
else:
print "No missing files"
print("No missing files")

if extras:
print "%d extra files (%s)" % (extras, format_memory(extra_bytes))
print("%d extra files (%s)" % (extras, format_memory(extra_bytes)))
else:
print "No extra files"
print("No extra files")
39 changes: 21 additions & 18 deletions download.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import gzip
import os
import urllib2
import threading
import time
import Queue
import StringIO
from checksum import calc_checksum
from format_memory import format_memory

import progress

try:
import urllib2
from cStringIO import StringIO
import Queue
except ImportError:
import urllib.request as urllib2
from io import StringIO
import queue as Queue


DOWNLOAD_THREAD_COUNT = 12

def get_url_root():
return 'http://res.eveonline.ccpgames.com'


def DownloadResourceFile(target_url, expected_checksum, target_path):
try:
contents = urllib2.urlopen(target_url)
Expand All @@ -25,7 +31,7 @@ def DownloadResourceFile(target_url, expected_checksum, target_path):
data = contents.read()
headers = contents.info()
if ('content-encoding' in headers.keys() and headers['content-encoding']=='gzip'):
sio = StringIO.StringIO(data)
sio = StringIO(data)
gzipper = gzip.GzipFile(fileobj=sio)
data = gzipper.read()

Expand Down Expand Up @@ -98,13 +104,12 @@ def f_proc_file(f):
break
except Exception as e:
import traceback
print traceback.format_exc(e)
print(traceback.format_exc(e))


def download_missing_files(res_folder, files_to_download):
q = Queue.Queue()
for f in files_to_download:
q.put(f)
[q.put(f) for f in files_to_download]

downloaded_files = 0
old_size = q.qsize()
Expand Down Expand Up @@ -136,17 +141,15 @@ def download_missing_files(res_folder, files_to_download):
num_failed += t.failed
num_succeeded += t.succeeded
if t.messages:
print t.messages
print(t.messages)

return num_succeeded, num_failed

except KeyboardInterrupt:
progress.clear()
print "Stopping download threads"
for t in thread_list:
t.stop()
for t in thread_list:
t.join()
print("Stopping download threads")
[t.stop() for t in thread_list]
[t.join() for t in thread_list]
raise

def scan_missing_files(index, res_folder):
Expand All @@ -168,15 +171,15 @@ def scan_missing_files(index, res_folder):
missing_bytes_on_disk += entry.size_in_bytes

progress.clear()
print "%6.1d files missing - %10.10s - %10.10s on disk\r" % \
(missing, format_memory(missing_bytes), format_memory(missing_bytes_on_disk))
print
print("%6.1d files missing - %10.10s - %10.10s on disk\r" % \
(missing, format_memory(missing_bytes), format_memory(missing_bytes_on_disk)))
print('')

return missing_files


def download_cache(index, res_folder):
missing_files = scan_missing_files(index, res_folder)
num_succeeded, num_failed = download_missing_files(res_folder, missing_files)
print "Downloaded %d files (%d failed)" % (num_succeeded, num_failed)
print("Downloaded %d files (%d failed)" % (num_succeeded, num_failed))

8 changes: 4 additions & 4 deletions move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def move_cache(src, dest):
if sys.platform != "darwin":
if os.path.exists(dest):
if os.path.isfile(dest):
print "'%s' exists as a file - can't move SharedCache folder" % dest
print("'%s' exists as a file - can't move SharedCache folder" % dest)
sys.exit(1)

print "'%s' already exists - can't move SharedCache folder" % dest
print("'%s' already exists - can't move SharedCache folder" % dest)
sys.exit(1)

try:
Expand All @@ -21,6 +21,6 @@ def move_cache(src, dest):

set_shared_cache_folder(dest)

print "SharedCache location has been moved to '%s'" % dest
print("SharedCache location has been moved to '%s'" % dest)
else:
print "The SharedCache location cannot be moved on Mac"
print("The SharedCache location cannot be moved on Mac")
20 changes: 12 additions & 8 deletions paths_win.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import _winreg

try:
import _winreg as winreg
except ImportError:
import winreg
import os


Expand All @@ -8,10 +12,10 @@ def get_shared_cache_folder():
If there is no entry, then we create one.
:return:
"""
_winreg.aReg = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
winreg.aReg = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
try:
key = _winreg.OpenKey(_winreg.aReg, r"SOFTWARE\CCP\EVEONLINE")
path, _ = _winreg.QueryValueEx(key, "CACHEFOLDER")
key = winreg.OpenKey(winreg.aReg, r"SOFTWARE\CCP\EVEONLINE")
path, _ = winreg.QueryValueEx(key, "CACHEFOLDER")
except OSError:
return None
return path
Expand All @@ -25,11 +29,11 @@ def set_shared_cache_folder(folder_path):
raise ValueError("Could not create directory {}".format(folder_path))
folder_path = os.path.normpath(folder_path) + os.sep

key_eveonline = _winreg.CreateKey(_winreg.aReg, r"SOFTWARE\CCP\EVEONLINE")
_winreg.SetValueEx(key_eveonline, "CACHEFOLDER", 0, _winreg.REG_SZ, folder_path)
key_eveonline = winreg.CreateKey(winreg.aReg, r"SOFTWARE\CCP\EVEONLINE")
winreg.SetValueEx(key_eveonline, "CACHEFOLDER", 0, winreg.REG_SZ, folder_path)

key_eveprobe = _winreg.CreateKey(_winreg.aReg, r"SOFTWARE\CCP\EVEPROBE")
_winreg.SetValueEx(key_eveprobe, "CACHEFOLDER", 0, _winreg.REG_SZ, folder_path)
key_eveprobe = winreg.CreateKey(winreg.aReg, r"SOFTWARE\CCP\EVEPROBE")
winreg.SetValueEx(key_eveprobe, "CACHEFOLDER", 0, winreg.REG_SZ, folder_path)


def get_index_path(hint):
Expand Down
6 changes: 2 additions & 4 deletions purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def delete_extra_files(index_by_cached_names, res_folder):


def purge_cache(index, res_folder):
index_by_cached_names = {}
for entry in index:
index_by_cached_names[entry.cached_name] = entry
index_by_cached_names = {ntry.cached_name: ntry for ntry in index}

extras = delete_extra_files(index_by_cached_names, res_folder)

print "Deleted %6.1d extra files from cache folder" % extras
print("Deleted %6.1d extra files from cache folder" % extras)
22 changes: 10 additions & 12 deletions rescache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def _get_index(filename):
with open(index_path) as f:
index = parse_index(f)
except IOError:
print "Couldn't open index file: %s" % index_path
print("Couldn't open index file: %s" % index_path)
sys.exit(1)
return index


def _get_res_folder(args):
if not args.cache:
print "Shared cache folder location has not been set"
print("Shared cache folder location has not been set")
sys.exit(1)
return os.path.join(args.cache, "ResFiles")

Expand All @@ -63,20 +63,20 @@ def move_command(args):


def run_interactive():
print "rescache is a tool for verifying and managing the EVE shared resource cache."
print
print "The current shared cache location is\n\t%s" % get_shared_cache_folder()
print
print("rescache is a tool for verifying and managing the EVE shared resource cache.")
print('')
print("The current shared cache location is\n\t%s" % get_shared_cache_folder())
print('')

res_folder = os.path.join(get_shared_cache_folder(), "ResFiles")
index = _get_index(DEFAULT_INDEX_FILENAME)

print "Verifying cache integrity"
print("Verifying cache integrity")
corrupt, missing = verify_cache(index, res_folder)
print
print('')

if corrupt:
print "%d corrupt files were deleted" % corrupt
print("%d corrupt files were deleted" % corrupt)

if missing:
answer = raw_input("Would you like to download missing files now? (y/n)")
Expand All @@ -87,7 +87,6 @@ def run_interactive():




def main():
progress.stream = sys.stdout

Expand Down Expand Up @@ -133,10 +132,9 @@ def main():

try:
args.func(args)

except KeyboardInterrupt:
progress.clear()
print "Operation cancelled"
print("Operation cancelled")
sys.exit(1)


Expand Down
6 changes: 3 additions & 3 deletions verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def verify_cache(index, res_folder):
pass

progress.clear()
print "Verified %d files:" % num_files
print " %6.1d files corrupt" % corrupt
print " %6.1d files not yet downloaded" % missing
print("Verified %d files:" % num_files)
print(" %6.1d files corrupt" % corrupt)
print(" %6.1d files not yet downloaded" % missing)

return corrupt, missing