Commit 8c8184f0b35c2e3524d98c9a03fecd4d15700500
- Diff rendering mode:
- inline
- side by side
src/cli.py
(25 / 0)
|   | |||
| 1 | # EVE-Central.com Contribtastic | ||
| 2 | # Copyright (C) 2005-2010 Yann Ramin | ||
| 3 | # | ||
| 4 | # This program is free software; you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation; either version 2 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License (in file COPYING) for more details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program; if not, write to the Free Software | ||
| 16 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 17 | |||
| 18 | |||
| 19 | import cli.upload | ||
| 20 | from cli.config import Config | ||
| 21 | |||
| 22 | config_obj = Config() | ||
| 23 | job = cli.upload.UploadPayload(config_obj['evepath'][0], None, | ||
| 24 | config_obj['character_id'], config_obj['backup']) | ||
| 25 | cli.upload.upload_data(job) |
src/cli.sh
(5 / 0)
|   | |||
| 1 | #!/bin/bash | ||
| 2 | export DYLD_LIBRARY_PATH=../libevecache/ | ||
| 3 | cp ../libevecache/_evecache.dylib cli/_evecache.so | ||
| 4 | cp ../libevecache/lib/evecache.py cli/ | ||
| 5 | python2.6 cli.py |
src/cli/config.py
(177 / 0)
|   | |||
| 1 | # python | ||
| 2 | # EVE-Central.com Contribtastic | ||
| 3 | # Copyright (C) 2005-2010 Yann Ramin | ||
| 4 | # | ||
| 5 | # This program is free software; you can redistribute it and/or modify | ||
| 6 | # it under the terms of the GNU General Public License as published by | ||
| 7 | # the Free Software Foundation; either version 2 of the License, or | ||
| 8 | # (at your option) any later version. | ||
| 9 | # | ||
| 10 | # This program is distributed in the hope that it will be useful, | ||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | # GNU General Public License (in file COPYING) for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU General Public License | ||
| 16 | # along with this program; if not, write to the Free Software | ||
| 17 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 18 | |||
| 19 | |||
| 20 | import sys | ||
| 21 | import os | ||
| 22 | import pickle | ||
| 23 | import time | ||
| 24 | |||
| 25 | try: | ||
| 26 | from win32com.shell import shell, shellcon | ||
| 27 | import wx | ||
| 28 | except: | ||
| 29 | pass | ||
| 30 | |||
| 31 | |||
| 32 | def find_first_path(path, pref = None): | ||
| 33 | dirlist = os.listdir(path) | ||
| 34 | |||
| 35 | if pref is None: | ||
| 36 | return dirlist[0] | ||
| 37 | |||
| 38 | for p in pref: | ||
| 39 | if p in dirlist or unicode(p) in dirlist: | ||
| 40 | return p | ||
| 41 | return dirlist[0] | ||
| 42 | |||
| 43 | |||
| 44 | def default_location(): | ||
| 45 | if sys.platform == 'win32': | ||
| 46 | |||
| 47 | document_folder = "c:/" | ||
| 48 | try: | ||
| 49 | document_folder = os.path.join( shell.SHGetFolderPath( 0, | ||
| 50 | shellcon.CSIDL_LOCAL_APPDATA, | ||
| 51 | 0, 0 ), 'CCP', 'EVE', ) | ||
| 52 | document_folder = os.path.join ( document_folder, | ||
| 53 | find_first_path(document_folder, ['232']), | ||
| 54 | 'cache', 'MachoNet', '87.237.38.200') | ||
| 55 | document_folder = os.path.join ( document_folder, | ||
| 56 | find_first_path(document_folder), 'CachedMethodCalls') | ||
| 57 | |||
| 58 | except: | ||
| 59 | pass | ||
| 60 | elif sys.platform == 'darwin': | ||
| 61 | from Carbon import Folder, Folders | ||
| 62 | folderref = Folder.FSFindFolder( Folders.kUserDomain, Folders.kPreferencesFolderType, False ) | ||
| 63 | document_folder = os.path.join( folderref.as_pathname(), 'EVE Online Preferences', 'p_drive', 'Local Settings', 'Application Data', 'CCP', 'EVE' ) | ||
| 64 | document_folder = os.path.join ( document_folder, | ||
| 65 | find_first_path(document_folder, ['235']), | ||
| 66 | 'cache', 'MachoNet', '87.237.38.200') | ||
| 67 | document_folder = os.path.join ( document_folder, | ||
| 68 | find_first_path(document_folder), 'CachedMethodCalls') | ||
| 69 | |||
| 70 | else: | ||
| 71 | document_folder = '' # don't know what the linux client has | ||
| 72 | document_folder = os.path.normpath( document_folder ) | ||
| 73 | |||
| 74 | return document_folder | ||
| 75 | |||
| 76 | |||
| 77 | class Config(object): | ||
| 78 | |||
| 79 | CONFIG_VERSION = '2.0-alpha1' | ||
| 80 | |||
| 81 | |||
| 82 | def __init__(self): | ||
| 83 | self.config_obj = {} | ||
| 84 | self.reinit = self.load_config() | ||
| 85 | |||
| 86 | |||
| 87 | def __getitem__(self, key): | ||
| 88 | return self.config_obj[key] | ||
| 89 | |||
| 90 | def __setitem__(self, key, value): | ||
| 91 | ret = self.config_obj[key] = value | ||
| 92 | self.save_config() | ||
| 93 | return ret | ||
| 94 | |||
| 95 | def __len__(self): | ||
| 96 | return len(self.config_obj) | ||
| 97 | |||
| 98 | def __delitem__(self, key): | ||
| 99 | del self.config_obj[key] | ||
| 100 | |||
| 101 | |||
| 102 | def default_data(self): | ||
| 103 | |||
| 104 | loc = default_location() | ||
| 105 | loc = [loc] | ||
| 106 | |||
| 107 | self.config_obj = { 'version' : Config.CONFIG_VERSION, | ||
| 108 | 'path_set' : False, | ||
| 109 | 'backup' : 'backup', | ||
| 110 | 'evepath' : loc, | ||
| 111 | 'character_name' : 'Anonymous', | ||
| 112 | 'character_id' : 0, | ||
| 113 | 'last_upload_time' : time.time() | ||
| 114 | } | ||
| 115 | |||
| 116 | def save_config(self): | ||
| 117 | path = "" | ||
| 118 | if sys.platform == 'darwin': | ||
| 119 | from Carbon import Folder, Folders | ||
| 120 | folderref = Folder.FSFindFolder( Folders.kUserDomain, Folders.kPreferencesFolderType, False ) | ||
| 121 | path = os.path.join( folderref.as_pathname(), 'eve-central-cli-upload' ) | ||
| 122 | else: | ||
| 123 | sp = wx.StandardPaths.Get() | ||
| 124 | wx.GetApp().SetAppName("EVE-Central MarketUploader") | ||
| 125 | path = sp.GetUserLocalDataDir() | ||
| 126 | |||
| 127 | |||
| 128 | try: | ||
| 129 | os.mkdir(path) | ||
| 130 | except: | ||
| 131 | pass | ||
| 132 | |||
| 133 | file = open( os.path.normpath( os.path.join( path, 'data.pickle' ) ), "w") | ||
| 134 | |||
| 135 | pickle.dump(self.config_obj, file) | ||
| 136 | |||
| 137 | file.close() | ||
| 138 | |||
| 139 | |||
| 140 | |||
| 141 | def load_config(self): | ||
| 142 | path = "" | ||
| 143 | if sys.platform == 'darwin': | ||
| 144 | from Carbon import Folder, Folders | ||
| 145 | folderref = Folder.FSFindFolder( Folders.kUserDomain, Folders.kPreferencesFolderType, False ) | ||
| 146 | path = os.path.join( folderref.as_pathname(), 'eve-central-cli-upload' ) | ||
| 147 | else: | ||
| 148 | sp = wx.StandardPaths.Get() | ||
| 149 | wx.GetApp().SetAppName("EVE-Central MarketUploader") | ||
| 150 | path = sp.GetUserLocalDataDir() | ||
| 151 | |||
| 152 | ret = 0 | ||
| 153 | file = None | ||
| 154 | try: | ||
| 155 | file = open( os.path.normpath( os.path.join( path, 'data.pickle' ) ), "r") | ||
| 156 | ret = 0 | ||
| 157 | self.config_obj = pickle.load(file) | ||
| 158 | |||
| 159 | except: | ||
| 160 | if file: | ||
| 161 | file.close() | ||
| 162 | file = None | ||
| 163 | |||
| 164 | self.default_data() | ||
| 165 | self.save_config() | ||
| 166 | return -1 | ||
| 167 | |||
| 168 | finally: | ||
| 169 | if file: | ||
| 170 | file.close() | ||
| 171 | |||
| 172 | if self.config_obj['version'] != Config.CONFIG_VERSION: | ||
| 173 | self.default_data() | ||
| 174 | self.save_config() | ||
| 175 | ret = -1 | ||
| 176 | |||
| 177 | return ret |
src/cli/upload.py
(180 / 0)
|   | |||
| 1 | # EVE-Central.com Contribtastic | ||
| 2 | # Copyright (C) 2005-2010 Yann Ramin | ||
| 3 | # | ||
| 4 | # This program is free software; you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation; either version 2 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License (in file COPYING) for more details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program; if not, write to the Free Software | ||
| 16 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 17 | |||
| 18 | |||
| 19 | import os | ||
| 20 | import re | ||
| 21 | import exceptions | ||
| 22 | import sys | ||
| 23 | import urllib | ||
| 24 | import stat | ||
| 25 | from cStringIO import StringIO | ||
| 26 | |||
| 27 | from threading import Thread | ||
| 28 | from Queue import Queue | ||
| 29 | import evecache | ||
| 30 | from cli.config import Config | ||
| 31 | |||
| 32 | |||
| 33 | ProgramVersion = 2000 | ||
| 34 | ProgramVersionNice = "2.0" | ||
| 35 | CheckVersion = 1031 | ||
| 36 | |||
| 37 | |||
| 38 | class UploadPayload(object): | ||
| 39 | def __init__(self, path, win, userid, backup): | ||
| 40 | self.path = path | ||
| 41 | self.win = win | ||
| 42 | self.userid = userid | ||
| 43 | self.backup = backup | ||
| 44 | |||
| 45 | class UploadThread(Thread): | ||
| 46 | def __init__(self): | ||
| 47 | Thread.__init__(self) | ||
| 48 | self.setDaemon(False) | ||
| 49 | self.queue = Queue() | ||
| 50 | |||
| 51 | def trigger(self, payload): | ||
| 52 | self.queue.put(payload) | ||
| 53 | |||
| 54 | |||
| 55 | def run(self): | ||
| 56 | while True: | ||
| 57 | payload = self.queue.get() | ||
| 58 | try: | ||
| 59 | upload_data(payload) | ||
| 60 | except Exception as e: | ||
| 61 | sys.stderr.write(e) | ||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | class ProtocolVersionMismatch(exceptions.Exception): | ||
| 66 | pass | ||
| 67 | |||
| 68 | |||
| 69 | def check_protocol(): | ||
| 70 | pc = urllib.urlopen("http://eve-central.com/protocol_version.txt") | ||
| 71 | version = pc.readline().strip() | ||
| 72 | pc.close() | ||
| 73 | if version != "1": | ||
| 74 | raise ProtocolVersionMismatch | ||
| 75 | |||
| 76 | |||
| 77 | def check_client(): | ||
| 78 | global ProgramVersion | ||
| 79 | cv = urllib.urlopen("http://eve-central.com/client_version.txt") | ||
| 80 | fversion = cv.readline().strip() | ||
| 81 | version = cv.readline().strip() | ||
| 82 | version = int(version) | ||
| 83 | cv.close() | ||
| 84 | if version > ProgramVersion: | ||
| 85 | return fversion | ||
| 86 | else: | ||
| 87 | return True | ||
| 88 | |||
| 89 | |||
| 90 | def perform_upload(typename, lines, userid, times, cache = False, region = 0, typeid = 0): | ||
| 91 | submitdata = urllib.urlencode({'typename' : typename, 'data' : lines, | ||
| 92 | 'userid': userid , 'timestamp': times, 'cache': cache, | ||
| 93 | 'region' : region, 'typeid' : typeid}) | ||
| 94 | |||
| 95 | h = urllib.urlopen("http://eve-central.com/datainput.py/inputdata", submitdata) | ||
| 96 | print h.read() # Gobble up result | ||
| 97 | h.close() | ||
| 98 | |||
| 99 | |||
| 100 | |||
| 101 | |||
| 102 | def upload_data(job): | ||
| 103 | |||
| 104 | dirl = [] | ||
| 105 | upcount = 0 | ||
| 106 | |||
| 107 | try: | ||
| 108 | dirl = os.listdir(job.path) | ||
| 109 | except Exception,e: | ||
| 110 | print e | ||
| 111 | return None | ||
| 112 | |||
| 113 | config = Config() | ||
| 114 | |||
| 115 | highest_timestamp = config['last_upload_time'] | ||
| 116 | if highest_timestamp <= 1: | ||
| 117 | highest_timestamp = time.time() # Major error, do something vaguely intelligent | ||
| 118 | |||
| 119 | start_ts = highest_timestamp | ||
| 120 | print "UPLOAD START: TIMESTAMP CHECK IS > ",start_ts | ||
| 121 | |||
| 122 | for item in dirl: | ||
| 123 | if item[-6:] != ".cache": | ||
| 124 | continue | ||
| 125 | item = os.path.join(job.path, item) | ||
| 126 | statinfo = os.stat(item) | ||
| 127 | |||
| 128 | if statinfo.st_mtime <= start_ts: | ||
| 129 | print "IGNORE:",item | ||
| 130 | continue | ||
| 131 | |||
| 132 | if statinfo.st_mtime > highest_timestamp: | ||
| 133 | highest_timestamp = statinfo.st_mtime | ||
| 134 | |||
| 135 | print item, statinfo.st_mtime, highest_timestamp | ||
| 136 | |||
| 137 | try: | ||
| 138 | market_parser = evecache.MarketParser(str(item)) | ||
| 139 | if market_parser.valid() == True: | ||
| 140 | print "Valid" | ||
| 141 | entries = market_parser.getList() | ||
| 142 | |||
| 143 | region = entries.region() | ||
| 144 | typeid = entries.type() | ||
| 145 | orders = [] | ||
| 146 | orders1 = entries.getSellOrders() | ||
| 147 | orders2 = entries.getBuyOrders() | ||
| 148 | # Fix up STL SWIG types not being list() | ||
| 149 | for order in orders1: | ||
| 150 | orders.append(order) | ||
| 151 | for order in orders2: | ||
| 152 | orders.append(order) | ||
| 153 | |||
| 154 | print "Upload of ",typeid,region | ||
| 155 | csvOutput = StringIO() | ||
| 156 | print >>csvOutput, "CACHE GENERATED FILE HEADER" | ||
| 157 | for order in orders: | ||
| 158 | print >>csvOutput, order.toCsv() | ||
| 159 | |||
| 160 | #print csvOutput.getvalue() | ||
| 161 | perform_upload("", csvOutput.getvalue(), job.userid, statinfo.st_mtime, | ||
| 162 | True, region = region, typeid = typeid) | ||
| 163 | csvOutput.close() | ||
| 164 | upcount += 1 | ||
| 165 | else: | ||
| 166 | print "Not valid" | ||
| 167 | except Exception,e: | ||
| 168 | print e | ||
| 169 | |||
| 170 | config['last_upload_time'] = highest_timestamp | ||
| 171 | |||
| 172 | |||
| 173 | |||
| 174 | return upcount | ||
| 175 | |||
| 176 | if __name__ == "__main__": | ||
| 177 | config_obj = Config() | ||
| 178 | job = UploadPayload(config_obj['evepath'][0], self, | ||
| 179 | config_obj['character_id'], config_obj['backup']) | ||
| 180 | upload_data(job) |

