Advertisement
Guest User

listplugins.py

a guest
Apr 4th, 2019
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import sys
  5. import glob
  6. import heapq
  7. import time
  8. import platform
  9.  
  10.  
  11. def main():
  12.     """
  13.    List VCV plugins on your system sorted by last update date
  14.    (Untested on Linux and Mac)
  15.  
  16.    Usage:
  17.  
  18.    listplugins.py [count]
  19.  
  20.    count   number of plugins to list (default: 25)
  21.  
  22.    """
  23.  
  24.     try:
  25.         count = int(sys.argv[-1]) if len(sys.argv) > 1 else 25
  26.     except ValueError:
  27.         print("argument should be a number")
  28.         exit(1)
  29.  
  30.     if platform.system() == "Windows":
  31.         if os.environ.get('MSYSTEM'):
  32.             mask = os.path.join(os.environ['USERPROFILE'], "Documents", "Rack", "plugins")
  33.         else:
  34.             mask = os.path.expanduser("~/Documents/Rack/plugins")
  35.         mask += "/**/plugin.dll"
  36.     elif platform.system() == "Linux":
  37.         mask = os.path.expanduser("~/.Rack/plugins") + "/**/plugin.so"
  38.     elif platform.system() == "Darwin":
  39.         mask = os.path.expanduser("~/Documents/Rack/plugins") + "/**/plugin.dylib"
  40.     else:
  41.         print("unknown platform")
  42.         exit(1)
  43.  
  44.     filenames = heapq.nlargest(
  45.         count,
  46.         glob.glob(mask),
  47.         key=lambda f: os.stat(f).st_mtime
  48.     )
  49.  
  50.     for filename in filenames:
  51.         print(
  52.             "{}  {}".format(
  53.                 time.ctime(os.stat(filename).st_mtime),
  54.                 os.path.split(os.path.dirname(filename))[-1]
  55.             )
  56.         )
  57.  
  58.  
  59. if __name__ == "__main__":
  60.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement