def _getDifflist(branch): if not os.path.exists(gv.DIFF_LIST_PATH): os.makedirs(gv.DIFF_LIST_PATH) cfg = ConfigParser.ConfigParser(); cfg.read(gv.BUILD_INI_FILE) revision = cfg.get(gv.BUILD_INI_SEC, gv.CURRENT_REVISION) tmp = '# Current Svn Version: ' + revision + '\n' difftxt = gv.DIFF_LIST_PATH + '/' + branch + '.txt' if os.path.exists(difftxt): os.remove(difftxt) # revision cmd = 'svn log -vv -r ' + gv.SVN_BASE_REVISION + ':' + revision # branch cmd += ' ' + gv.LOCAL_CODE_PATH + '/' + branch # filter relative = gv.REMOTE_CODE_PATH[gv.REMOTE_CODE_PATH.find('/branches/'):] cmd += '| egrep "^ +[AMD]" | sed "s;' + relative + '/;;g" | sed "s;^ *;;g" | sed "s; *$;;g" | grep -v "' + relative + '"' diffcontent = commands.getoutput(cmd) tmp += _filterDiff(diffcontent) func.writeFile(difftxt, tmp)
def pkgFiles(branch): ins_cfg = gv.PACK_CONF_PATH + '/' + branch + '.cfg' cfgcontent = '' # whether need add ignore?? ini = gv.FILE_INI_PATH + '/' + branch + '.ini' cfgPsr = ConfigParser.ConfigParser() cfgPsr.read(ini) difflist = gv.DIFF_LIST_PATH + '/' + branch + '.txt' fileAdapter = open(difflist) for line in fileAdapter: line = line.strip() if line.find('#') == 0 or line.strip() == '': continue; (svnAct, svnpath) = line.split(' ') svnAct = svnAct.lower() if not cfgPsr.has_section(svnpath): if cfgPsr.has_section(svnpath + '/'): svnpath += '/' dictIni = _infoParser(cfgPsr.items(svnpath)) if dictIni['act'] == 'i': if gv.DEBUG_SWITCH == 1: if dictIni['typ'] == 'f': _sec_type = 'FILE' elif dictIni['typ'] == 'd': _sec_type = 'DIRS' else: _sec_type = 'null' func.tip('[SEC]: ' + svnpath + '\n[IGN]: ' + _sec_type + '\n[PTH]: ' + svnpath, '35') continue; if svnAct == 'd': dictIni['act'] = 'm' dictIni['mod'] = '0' dictIni['own'] = '0' dictIni['grp'] = '0' cfgcontent += _combineBaseCfg(dictIni) elif svnAct == 'm' or svnAct == 'a': dictIni['sec'] = svnpath dictIni['act'] = 'a' tmp = _combineAddCfg(dictIni) # if tmp == '': # func.errorReport('[' + svnpath + '] combine:\n' + str(dictIni)) cfgcontent += tmp func.writeFile(ins_cfg, cfgcontent)
def arrangeCfg(): ret = '' for item in gv.SVN_EACH_BRANCH: cfg = gv.PACK_CONF_PATH + '/' + item + '.cfg' ret = ret + open(cfg).read() cfgall = gv.PACK_CONF_PATH + '/files.cfg' if os.path.exists(cfgall): os.remove(cfgall) for item in gv.EXTRA_FILES: src = item[1:] tmp = 'a f ' + src + ' ' + item + ' root root 0644\n' ret += tmp # copy extra to files if os.path.basename(item) == 'version': cfgPsr = ConfigParser.ConfigParser() cfgPsr.read(gv.BUILD_INI_FILE) last = int(cfgPsr.get(gv.BUILD_INI_SEC, gv.CURRENT_BUILDNUM)) revision = cfgPsr.get(gv.BUILD_INI_SEC, gv.CURRENT_REVISION) latest = str(last + 1) cfgPsr.set(gv.BUILD_INI_SEC, 'build' + latest, revision) cfgPsr.set(gv.BUILD_INI_SEC, gv.CURRENT_BUILDNUM, latest) cfgPsr.write(open(gv.BUILD_INI_FILE, 'w')) func.tip('[Build]:' + latest + '\t[Revision]:' + revision, '31') verCfg = gv.ITM_VERSION + '-' + latest func.writeFile(gv.PACK_CONF_PATH + '/version', verCfg + '\n') func.writeFile(gv.PACK_CONF_PATH + '/revision', revision + '\n') verFile = gv.PACK_FILE_PATH + item if not os.path.exists(os.path.dirname(verFile)): os.makedirs(os.path.dirname(verFile)) cmd = 'sed \'s/^Last_Build_SN.*/Last_Build_SN=' + latest + '/\' ' + gv.EXTRA_PATH + '/' + os.path.basename(item) +' > ' + verFile os.system(cmd) else: srcExtra = gv.EXTRA_PATH + '/' + os.path.basename(item) dstExtra = gv.PACK_FILE_PATH + item if not os.path.exists(os.path.dirname(dstExtra)): os.makedirs(os.path.dirname(dstExtra)) shutil.copyfile(srcExtra, dstExtra) # sort -u listRet1 = ret.split('\n') listRet2 = list(set(listRet1)) listRet2.sort(key = listRet1.index) ret = '\n'.join(listRet2) func.writeFile(cfgall, ret) func.tip('Update Files.cfg Finish', '32'); func.tip('-------------------------------------');
def addStayPoint(DBPath, i): """ caculate stay point value in table GPS_points_i, value: 1 denotes the point is stay point value: 0 denotes the normal stap point step 1: find stay point according to rule: Distance(p1, p2)<D and TimeDiff(p1, p2)>T step 2: use direction change to drop extra stay points step 3: noise filtering """ conn = DBUtil.get_conn(DBPath) # find all points fetchAllPointSql = 'select * from GPS_points_' + str(i) allPointRecords = DBUtil.fetchAll(conn, fetchAllPointSql) if allPointRecords is None: print('fetch point set Fail!') return """ records: type list-> [(1, 3, 39.9752333333333, 116.330066666667, '2008/04/29 17:15:24', -1, -1, -1, 'non', 0, 0, 0, 0, 'none')......] id: 0 time: 4 lat: 2 lon: 3 distance: 7 velocity: 5 """ parameters = [] stayPointSet = [] recordLen = len(allPointRecords) index = 0 while index < recordLen: cur = allPointRecords[index] j = index + 1 token = 0 while j < recordLen: aft = allPointRecords[j] # if another trajectory bagins if aft[7] == -1: index = j token = 1 break dist = func.getDistance(cur[2], cur[3], aft[2], aft[3]) if dist > StayPoinDistThd: curTimeDiff = func.getTimeInterval(cur[4], aft[4]) if curTimeDiff > StayPoinTiThd: # index ~ j points are added to stayPointSet sIndex = index while sIndex < j: temp = allPointRecords[sIndex] stayPointSet.append((temp[0], temp[2], temp[3])) sIndex += 1 # output the stay points set # print(stayPointSet) """ check stay points set 1, abandon the case of traffic congestion """ # isTraCong = func.isTrafficCongestion(stayPointSet, # changeAngle, # changeRate) # if isTraCong == 1: # stayPointSet.clear() # break """ check stay points set 2 (noise filtering), get content: [(39, 39.8146666666667, 119.476816666667, 0),......], """ resPointList = func.noiseFilter(stayPointSet, 3) """ insert stay points into table GPS_points_i field: is_stay_point """ for item in resPointList: parameters.append((item[3], item[0])) # print("resPointList's size:" + str(len(resPointList))) # print(resPointList) func.writeFile( 'stay_point_set_result.txt', "resPointList's size: " + str(len(resPointList))) func.writeFile('stay_point_set_result.txt', str(resPointList)) func.writeFile('stay_point_set_result.txt', "\n\n") updateSql = "update GPS_points_" + str(i) + \ " set is_stay_point = 1, is_deleted = ? where id = ?" # DBUtil.update(conn, updateSql, parameters) # clear the stay points set resPointList.clear() stayPointSet.clear() parameters.clear() index = j token = 1 break else: break j += 1 # end while if token != 1: index += 1 DBUtil.closeDB(conn)
import requests as req import time import os import func from bs4 import BeautifulSoup as bs4 holderFile = "content.txt" address = 'https://oldschool.runescape.com/' page = req.get(address) sourceCode = bs4(page.content, 'html.parser') newsSection = sourceCode.find('section', class_="content") cleanedSection = newsSection.text infoList = [] func.writeFile(holderFile, cleanedSection) filledList = func.readFile(holderFile, infoList) readMoreRemover = "Read More..." filledList[1] = filledList[1] + "\n" for x in filledList: if x[:12] == "Game Updates": indexTrackerTitle = filledList.index(x) - 1 filledList[ indexTrackerTitle] = "Title: " + filledList[indexTrackerTitle] indexTrackerDescription = filledList.index(x) + 1 filledList[indexTrackerDescription] = "Description: " + filledList[ indexTrackerDescription] + "\n" new = "Date: " + x filledList[filledList.index(x)] = new if x[:14] == "Future Updates": indexTrackerTitle = filledList.index(x) - 1 filledList[
def checkCfgIni(): illegals = 0; if os.path.exists(gv.CHECK_CONF_PATH): os.system('rm -rf ' + gv.CHECK_CONF_PATH) os.makedirs(gv.CHECK_CONF_PATH) for branch in gv.SVN_EACH_BRANCH: # diff list file_diff = gv.DIFF_LIST_PATH + '/' + branch + '.txt' file_inis = gv.FILE_INI_PATH + '/' + branch + '.ini' cfgPsr = ConfigParser.ConfigParser() cfgPsr.read(file_inis) _cfgStr = '' _errStr = '' # read each line Of diff.txt file_reader = open(file_diff) for line in file_reader: line = line.strip(); # comment line & null line, skip; if line.find('#') == 0 or line.strip() == '': continue; (act, codepath) = line.split(' '); if _checkInSkipDirs(codepath) == 1: _cfgStr += codepath + '\n [action]: IGNORE [reason]: belong to SVN_SKIP_DIRS\n'; continue; # errorReport if not cfgPsr.has_section(codepath): if cfgPsr.has_section(codepath + '/'): codepath += '/'; else: _errStr += codepath + '\n [reason]: NOT EXSITS\n' continue; dictIni = _parserInfo(cfgPsr.items(codepath)); if dictIni['typ'] == '' and dictIni['act'] == '' and dictIni['src'] == '' and dictIni['dst'] == '' and dictIni['mod'] == '' and dictIni['own'] == '' and dictIni['grp'] == '': _errStr += codepath + '\n [reason]: PROPERTIES UNDEFINED\n'; continue; # Dirs, src & dst not allow multi if dictIni['typ'] == 'd': if (len(dictIni['src'].strip()) > 1) or (len(dictIni['dst'].strip()) > 1): _errStr += codepath + '\n [reason]: Dirs src/dst UnALLOWED MULTI'; continue; if dictIni['act'] == 'i': _cfgStr += codepath + '\n [act]: IGNORE\n [reason]: defined by '+ branch +'.ini\n'; continue; elif dictIni['act'] == 'z': _errStr += codepath + '\n [reason]: UNINITIALIEZED\n' continue; # check srcNums & dstNums _srcNums = str.count(dictIni['src'], '|') _dstNums = str.count(dictIni['dst'], '|') if not _srcNums == _dstNums: _errStr += codepath + '\n [reason]: SRC & DST NUMBERS NOT EQUAL\n' continue; # check src whether exist or not # exist 1 at least!! _srcCount = 0; _srcS = dictIni['src'].split('|'); for each in _srcS: if os.path.exists(gv.LOCAL_CODE_PATH + '/' + each): _srcCount += 1; if _srcCount == 0: if not act == 'D': _errStr += codepath + '\n [reason]: NOT FOUND SRC, BUT CHANGED\n' continue; # check dst, if not start with '/', error _dstCount = 0; _dstS = dictIni['dst'].split('|'); for each in _dstS: if not each.find('/') == 0: _errStr += codepath + '\n [reason]: DST PATH NOT START WITH \'/\'\n' # check finish _cfgStr += codepath + '\n [act]: ' + dictIni['act'] + ' \t[type]: ' + dictIni['typ'] + '\n' _cfgStr += ' [src]: ' + dictIni['src'] + '\n [dst]: ' + dictIni['dst'] + '\n' _cfgStr += ' [mod]: ' + dictIni['mod'] + ' \t[own]: ' + dictIni['own'] + ' \t[grp]: ' + dictIni['grp'] + '\n' func.writeFile(gv.CHECK_CONF_PATH + '/' + branch + '-cfg.txt', _cfgStr, 'w'); func.writeFile(gv.CHECK_CONF_PATH + '/' + branch + '-err.txt', _errStr, 'w'); if not len(_errStr) == 0: illegals += 1; func.tip(branch + '.ini EXISTS ERRORS', '31') if gv.DEBUG_SWITCH == 1: if not len(_errStr) == 0: func.tip(_errStr, '31'); func.tip('++++ check ini ' + branch + ' \t++++'); if not illegals == 0: func.errorReport('INI Config Illegal, Go "' + gv.CHECK_CONF_PATH + '" to check') func.tip('INI Config Check Finished.', '32')
def _updateCfgIni(branch): newini = new_ini_path + '/' + branch + '.ini' baseini = gv.FILE_INI_PATH + '/' + branch + '.ini' tmp = '; ' + branch + ' INI ;' + '\n' func.writeFile(newini, tmp, 'w') baseConfig = ConfigParser.ConfigParser(); baseConfig.read(baseini) FileAdapter = open(branch + '.list') for item in FileAdapter: item = branch + '/' + item.strip() if baseConfig.has_section(item): optionTyp = baseConfig.get(item, 'typ'); optionTyp = 'typ = ' + optionTyp + '\n'; optionAct = baseConfig.get(item, 'act'); optionAct = 'act = ' + optionAct + '\n'; optionSrc = baseConfig.get(item, 'src'); optionSrc = 'src = ' + optionSrc + '\n'; optionDst = baseConfig.get(item, 'dst'); optionDst = 'dst = ' + optionDst + '\n'; optionMod = baseConfig.get(item, 'mod'); optionMod = 'mod = ' + optionMod + '\n'; optionOwn = baseConfig.get(item, 'own'); optionOwn = 'own = ' + optionOwn + '\n'; optionGrp = baseConfig.get(item, 'grp'); optionGrp = 'grp = ' + optionGrp + '\n'; oprionDsc = baseConfig.get(item, 'dsc'); oprionDsc = 'dsc = ' + oprionDsc + '\n' optionSec = '[' + item + ']\n' tmp = optionSec + optionTyp + optionAct + optionSrc + optionDst + optionMod + optionOwn + optionGrp + oprionDsc + '\n' else: if item[-1] == '/': optionTyp = 'D' else: optionTyp = 'F' optionTyp = 'typ = ' + optionTyp + '\n' optionMOG = '' if branch == 'gui': optionAct = 'act = A\n' optionSrc = 'src = ' + item + '\n' optionDst = 'dst = ' + item.replace('gui/html','/var/www/html') + '\n' if item.find('gui/html/scripts') == -1: optionMod = 'mod = 0644\n' optionOwn = 'own = apache\n' optionGrp = 'grp = apache\n' else: optionMod = 'mod = 4650\n' optionOwn = 'own = root\n' oprionGrp = 'grp = apache\n' else: optionAct = 'act = Z\n' optionMod = 'mod = 0755\n' optionOwn = 'own = root\n' optionGrp = 'grp = root\n' optionDst = 'dst = \n' optionSec = '[' + item + ']\n' optionSrc = 'src = ' + item + '\n' oprionDsc = 'dsc = \n' tmp = optionSec + optionTyp + optionAct + optionSrc + optionDst + optionMod + optionOwn + optionGrp + oprionDsc + '\n' func.writeFile(newini, tmp, 'a') FileAdapter.close() # files classify listName = branch + '.list' initName = branch + '.ini' os.remove(listName) if not os.path.exists(gv.FILE_INI_PATH + '/tmp'): os.mkdir(gv.FILE_INI_PATH + '/tmp') cfg = ConfigParser.ConfigParser() cfg.read(gv.BUILD_INI_FILE) revision = cfg.get(gv.BUILD_INI_SEC, gv.CURRENT_REVISION) shutil.move(gv.FILE_INI_PATH + '/' + initName, gv.FILE_INI_PATH + '/tmp/' + revision + '-' + branch + '.ini') shutil.move(initName, gv.FILE_INI_PATH + '/' + initName)