def sendAnalytics( name, version="1.0.0", an="StudioLibrary", tid=None, ): """ Send an analytic event to google analytics. This is only used once and is not used to send any personal/user data. Example: # logs an event named "mainWindow" sendAnalytics("mainWindow") :type name: str :type version: str :type an: str :type tid: str :rtype: None """ if not studiolibrary.config().get('analyticsEnabled'): return tid = tid or studiolibrary.config().get('analyticsId') cid = userUuid() url = "http://www.google-analytics.com/collect?" \ "v=1" \ "&ul=en-us" \ "&a=448166238" \ "&_u=.sB" \ "&_v=ma1b3" \ "&qt=2500" \ "&z=185" \ "&tid={tid}" \ "&an={an}" \ "&av={av}" \ "&cid={cid}" \ "&t=appview" \ "&cd={name}" url = url.format( tid=tid, an=an, av=version, cid=cid, name=name, ) def _send(url): try: url = url.replace(" ", "") f = urllib2.urlopen(url, None, 1.0) except Exception: pass t = threading.Thread(target=_send, args=(url, )) t.start()
def recursiveDepth(self): """ Return the recursive search depth. :rtype: int """ return studiolibrary.config().get('recursiveSearchDepth')
def settingsPath(self): """ Get the settings path for the LibraryWindow. :rtype: str """ formatString = studiolibrary.config().get('settingsPath') return studiolibrary.formatPath(formatString)
def settingsPath(): """ Get the settings path from the config file. :rtype: str """ formatString = studiolibrary.config().get('settingsPath') return studiolibrary.formatPath(formatString)
def databasePath(self): """ Return the path to the database. :rtype: str """ formatString = studiolibrary.config().get('databasePath') return studiolibrary.formatPath(formatString, path=self.path())
def tempPath(*args): """ Get the temp directory set in the config. :rtype: str """ temp = studiolibrary.config().get("tempPath") return normPath(os.path.join(formatPath(temp), *args))
def readMetadata(self): """ Read the metadata for the item from disc. :rtype: dict """ formatString = studiolibrary.config().get('metadataPath') path = studiolibrary.formatPath(formatString, self.path()) metadata = studiolibrary.readJson(path) return metadata
def saveMetadata(self, metadata): """ Save the given metadata to disc. :type metadata: dict """ formatString = studiolibrary.config().get('metadataPath') path = studiolibrary.formatPath(formatString, self.path()) studiolibrary.saveJson(path, metadata) self.setMetadata(metadata)
def itemFromPath(path, **kwargs): """ Return a new item instance for the given path. :type path: str :rtype: studiolibrary.LibraryItem or None """ path = normPath(path) for ignore in studiolibrary.config().get('ignorePaths', []): if ignore in path: return None for cls in registeredItems(): if cls.match(path): return cls(path, **kwargs)
def showInFolder(path): """ Show the given path in the system file explorer. :type path: unicode :rtype: None """ if isWindows(): # os.system() and subprocess.call() can't pass command with # non ascii symbols, use ShellExecuteW directly cmd = ctypes.windll.shell32.ShellExecuteW else: cmd = os.system args = studiolibrary.config().get('showInFolderCmd') if args: if isinstance(args, basestring): args = [args] elif isLinux(): args = [u'xdg-open "{path}"&'] elif isWindows(): args = [ None, u'open', u'explorer.exe', u'/n,/select, "{path}"', None, 1 ] elif isMac(): args = [u'open -R "{path}"'] # Normalize the pathname for windows path = os.path.normpath(path) for i, a in enumerate(args): if isinstance(a, basestring) and '{path}' in a: args[i] = a.format(path=path) logger.info("Call: '%s' with arguments: %s", cmd.__name__, args) cmd(*args)
def showInFolder(path): """ Show the given path in the system file explorer. :type path: unicode :rtype: None """ if isWindows(): # os.system() and subprocess.call() can't pass command with # non ascii symbols, use ShellExecuteW directly cmd = ctypes.windll.shell32.ShellExecuteW else: cmd = os.system args = studiolibrary.config().get('showInFolderCmd') if args: if isinstance(args, six.string_types): args = [args] elif isLinux(): args = [u'xdg-open "{path}"&'] elif isWindows(): args = [None, u'open', u'explorer.exe', u'/n,/select, "{path}"', None, 1] elif isMac(): args = [u'open -R "{path}"'] # Normalize the pathname for windows path = os.path.normpath(path) for i, a in enumerate(args): if isinstance(a, six.string_types) and '{path}' in a: args[i] = a.format(path=path) logger.info("Call: '%s' with arguments: %s", cmd.__name__, args) cmd(*args)
def sendAnalytics( name, version="1.0.0", an="StudioLibrary", tid=None, ): """ Send an analytic event to google analytics. This is only used once and is not used to send any personal/user data. Example: # logs an event named "mainWindow" sendAnalytics("mainWindow") :type name: str :type version: str :type an: str :type tid: str :rtype: None """ def _send(url): try: url = url.replace(" ", "") f = urllib.request.urlopen(url) except Exception: pass if not studiolibrary.config().get('analyticsEnabled'): return tid = tid or studiolibrary.config().get('analyticsId') cid = userUuid() ul, _ = locale.getdefaultlocale() ul = ul.replace("_", "-").lower() # -- Legacy begin -- # This can be removed after October 2019 url = "http://www.google-analytics.com/collect?" \ "v=1" \ "&ul=en-us" \ "&a=448166238" \ "&_u=.sB" \ "&_v=ma1b3" \ "&qt=2500" \ "&z=185" \ "&tid={tid}" \ "&an={an}" \ "&av={av}" \ "&cid={cid}" \ "&t=appview" \ "&cd={name}" url = url.format( tid=tid, an=an, av=version, cid=cid, name=name, ) t = threading.Thread(target=_send, args=(url,)) t.start() # -- Legacy end -- # Page View tid = "UA-50172384-3" url = "https://www.google-analytics.com/collect?" \ "v=1" \ "&ul={ul}" \ "&tid={tid}" \ "&an={an}" \ "&av={av}" \ "&cid={cid}" \ "&t=pageview" \ "&dp=/{name}" \ "&dt={av}" \ url = url.format( tid=tid, an=an, av=version, cid=cid, name=name, ul=ul, ) t = threading.Thread(target=_send, args=(url,)) t.start()
def sendAnalytics( name, version="1.0.0", an="StudioLibrary", tid=None, ): """ Send an analytic event to google analytics. This is only used once and is not used to send any personal/user data. Example: # logs an event named "mainWindow" sendAnalytics("mainWindow") :type name: str :type version: str :type an: str :type tid: str :rtype: None """ def _send(url): try: url = url.replace(" ", "") f = urllib.request.urlopen(url) except Exception: pass if not studiolibrary.config().get('analyticsEnabled'): return tid = tid or studiolibrary.config().get('analyticsId') cid = userUuid() ul, _ = locale.getdefaultlocale() ul = ul.replace("_", "-").lower() # -- Legacy begin -- # This can be removed after October 2019 url = "http://www.google-analytics.com/collect?" \ "v=1" \ "&ul=en-us" \ "&a=448166238" \ "&_u=.sB" \ "&_v=ma1b3" \ "&qt=2500" \ "&z=185" \ "&tid={tid}" \ "&an={an}" \ "&av={av}" \ "&cid={cid}" \ "&t=appview" \ "&cd={name}" url = url.format( tid=tid, an=an, av=version, cid=cid, name=name, ) t = threading.Thread(target=_send, args=(url, )) t.start() # -- Legacy end -- # Page View tid = "UA-50172384-3" url = "https://www.google-analytics.com/collect?" \ "v=1" \ "&ul={ul}" \ "&tid={tid}" \ "&an={an}" \ "&av={av}" \ "&cid={cid}" \ "&t=pageview" \ "&dp=/{name}" \ "&dt={av}" \ url = url.format( tid=tid, an=an, av=version, cid=cid, name=name, ul=ul, ) t = threading.Thread(target=_send, args=(url, )) t.start()