def addTag(bot, update): chatId = update.message.chat_id if update.message.reply_to_message: replyTo = update.message.reply_to_message.from_user.id else: replyTo = update.message.from_user.id fromUser = update.message.from_user.id if db.isLimied(fromUser): update.message.reply_text( u"操作被拒绝: 速率限制", reply_to_message_id=update.message.message_id) db.addLimit(fromUser, chatId) for item in str(update.message.text).split(" "): tag = update.message.text[5:] db.addTag(replyTo, chatId, tag) if update.message.from_user: db.setUserName(getUserName(update.message.from_user), fromUser) if update.message.reply_to_message: db.setUserName(getUserName(update.message.reply_to_message.from_user), replyTo) update.message.reply_text(u"操作成功 添加了Tag", reply_to_message_id=update.message.message_id)
def createFollowingGameList(): username = utils.getUserName() if not username: utils.notification(PLUGIN.get_string(30095)) else: games = TWITCHTV.getFollowingGames(username) items = [CONVERTER.convertGameToListItem(element) for element in games] PLUGIN.set_content(utils.getContentType()) return items
def createFollowingList(): username = utils.getUserName() if not username: utils.notification(PLUGIN.get_string(30095)) else: streams = TWITCHTV.getFollowingStreams(username) liveStreams = [CONVERTER.convertStreamToListItem(stream) for stream in streams[Keys.LIVE]] liveStreams.insert(0, {'path': PLUGIN.url_for(endpoint='createFollowingList'), 'icon': Images.ICON, 'thumbnail': Images.THUMB, 'art': utils.theArt(), 'is_playable': False, 'label': PLUGIN.get_string(30012)}) liveStreams.append({'path': PLUGIN.url_for(endpoint='createFollowingList'), 'icon': Images.ICON, 'thumbnail': Images.THUMB, 'art': utils.theArt(), 'is_playable': False, 'label': PLUGIN.get_string(30013)}) liveStreams.extend([CONVERTER.convertFollowersToListItem(follower) for follower in streams[Keys.OTHERS]]) utils.refreshPreviews() PLUGIN.set_content(utils.getContentType()) return liveStreams
import fnmatch, os, re, sys import hooks, utils from exceptions import EupsException who = utils.getUserName() tagListFileExt = "tags" tagListFileTmpl = "%s." + tagListFileExt tagListFileRe = re.compile(r"^(\w\S*).%s$" % tagListFileExt) commRe = re.compile(r"\s*#.*$") class Tags(object): """ a manager of a set of known tag names. Tags are organized into groups; however, the same name may not be allowed in more than one group. Three groups are handled by default: global, pseudo, and user. """ # the group string name indicating the global tag group global_ = "_" # the group string name indicating the user tag group user = "******" # pseudo-tags used by the VRO pseudo = "_p" def __init__(self, globals=None, groups=[]): # a lookup of recognized tag names. These are separated into groups # of which three are generally used:
#!/usr/bin/env python """Creates a PC file with a selection of points from a BBox and level""" import argparse, traceback, time, os, psycopg2, datetime import utils # Check the LAStools is installed and that it is in the PATH before libLAS if utils.shellExecute('lasmerge -version').count('LAStools') == 0: raise Exception("LAStools lasmerge is not found!. Please check that it is in PATH and that it is before libLAS binaries") USERNAME = utils.getUserName() def argument_parser(): """ Define the arguments and return the parser object""" parser = argparse.ArgumentParser( description="""Creates a PC file with a selection of points from a BBox and level""") parser.add_argument('-s','--srid',default='',help='SRID',type=int, required=True) parser.add_argument('-e','--mail', default='',help='E-mail address to send e-mail after completion',type=str, required=True) parser.add_argument('-b','--bbox', default='', help='Bounding box for the points selection given as "minX minY maxX maxY"',required=True,type=str) parser.add_argument('-l','--level', default='',help='Level of data used for the generation (only used if the used table is the one with the potree data). If not provided the raw data is used',type=str) parser.add_argument('-d','--dbname',default=utils.DB_NAME,help='Postgres DB name [default ' + utils.DB_NAME + ']',type=str) parser.add_argument('-u','--dbuser', default=USERNAME,help='DB user [default ' + USERNAME + ']',type=str) parser.add_argument('-p','--dbpass', default='',help='DB pass',type=str) parser.add_argument('-t','--dbhost', default='',help='DB host',type=str) parser.add_argument('-r','--dbport', default='',help='DB port',type=str) parser.add_argument('-w','--baseurl', default='',help='Base URL for the output file (web access)',type=str) parser.add_argument('-f','--basepath', default='',help='Base path for the output file (internal access)',type=str) return parser def run(srid, userMail, level, bBox, dbName, dbPass, dbUser, dbHost, dbPort, baseURL, basePath):
def takeLocks(cmdName, path, lockType, nolocks=False, ntry=10, verbose=0): locks = [] if hooks.config.site.lockDirectoryBase is None: if verbose > 2: print >> utils.stdinfo, "Locking is disabled" nolocks = True if lockType is not None and not nolocks: if lockType == LOCK_EX: lockTypeName = "exclusive" else: lockTypeName = "shared" if verbose > 1: print >> utils.stdinfo, "Acquiring %s locks for command \"%s\"" % (lockTypeName, cmdName) dt = 1.0 # number of seconds to wait for d in path: makeLock = True # we can make the lock for i in range(1, ntry + 1): try: lockDir = os.path.join(getLockPath(d), _lockDir) getLockPath(d, create=True) os.mkdir(lockDir) except OSError, e: if lockType == LOCK_EX: lockPids = listLockers(lockDir, getPids=True) if len(lockPids) == 1 and lockPids[0] == os.environ.get("EUPS_LOCK_PID", "-1"): pass # OK, there's a lock but we know about it if verbose: print >> utils.stdinfo, "Lock is held by a parent, PID %d" % lockPids[0] else: if e.errno == errno.EEXIST: reason = "locks are held by %s" % " ".join(listLockers(lockDir)) else: reason = str(e) msg = "Unable to take exclusive lock on %s" % (d) if e.errno == errno.EACCES: if verbose >= 0: print >> utils.stdinfo, "%s; your command may fail" % (msg) utils.stdinfo.flush() makeLock = False break msg += ": %s" % (reason) if i == ntry: raise RuntimeError(msg) else: print >> utils.stdinfo, "%s; retrying" % msg utils.stdinfo.flush() time.sleep(dt) continue else: if not os.path.exists(lockDir): if verbose: print >> utils.stdwarn, "Unable to lock %s; proceeding with trepidation" % d return [] if not makeLock: continue if verbose > 2: print >> utils.stdinfo, "Creating lock directory %s" % (lockDir) # # OK, the lock directory exists. # # If we're a shared lock, we need to check that no-one holds an exclusive lock (or, if someone # does hold the lock, that we're the holder's child) # # N.b. the check isn't atomic, but that's conservative (we don't care if the exclusive lock's # dropped while we're pondering its existence) # lockers = listLockers(lockDir, "exclusive*") if len(lockers) > 0: if len(lockers) == 1 and \ os.environ.get("EUPS_LOCK_PID", "-1") == \ listLockers(lockDir, "exclusive*", getPids=True)[0]: pass else: raise RuntimeError(("Unable to take shared lock on %s: " + "an exclusive lock is held by %s") % (d, " ".join(lockers))) break # got the lock if not makeLock: continue if not os.environ.has_key("EUPS_LOCK_PID"): # remember the PID of the process taking the lock os.environ["EUPS_LOCK_PID"] = "%d" % os.getpid() os.putenv("EUPS_LOCK_PID", os.environ["EUPS_LOCK_PID"]) # # # Create a file in it # who = utils.getUserName() pid = os.getpid() lockFile = "%s-%s.%d" % (lockTypeName, who, pid) try: fd = os.open(os.path.join(lockDir, lockFile), os.O_EXCL | os.O_RDWR | os.O_CREAT) os.close(fd) except OSError, e: if e.errno != errno.EEXIST: # should not occur raise locks.append((lockDir, lockFile)) if verbose > 3: print >> utils.stdinfo, "Creating lockfile %s" % (os.path.join(lockDir, lockFile))
import fnmatch, os, re, sys import hooks, utils from exceptions import EupsException who = utils.getUserName() tagListFileExt = "tags" tagListFileTmpl = "%s." + tagListFileExt tagListFileRe = re.compile(r"^(\w\S*).%s$" % tagListFileExt) commRe = re.compile(r"\s*#.*$") class Tags(object): """ a manager of a set of known tag names. Tags are organized into groups; however, the same name may not be allowed in more than one group. Three groups are handled by default: global, pseudo, and user. """ # the group string name indicating the global tag group global_ = "_" # the group string name indicating the user tag group user = "******" # pseudo-tags used by the VRO pseudo = "_p" def __init__(self, globals=None, groups=[]): # a lookup of recognized tag names. These are separated into groups