Skip to content

Commit

Permalink
list videos
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Jul 1, 2012
1 parent bad36b7 commit 121014e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 12 deletions.
25 changes: 13 additions & 12 deletions downloadr/DownloadrWindow.py
Expand Up @@ -4,6 +4,7 @@
### END LICENSE

import os
import subprocess
import gettext

from gettext import gettext as _
Expand All @@ -17,6 +18,8 @@
from downloadr.AboutDownloadrDialog import AboutDownloadrDialog
from downloadr.PreferencesDownloadrDialog import PreferencesDownloadrDialog

from flashcache import get_pids, get_file_names

COL_PATH = 0
COL_PIXBUF = 1
COL_IS_DIRECTORY = 2
Expand All @@ -34,8 +37,7 @@ def finish_initializing(self, builder): # pylint: disable=E1002
self.PreferencesDialog = PreferencesDownloadrDialog

self.current_directory = os.path.realpath(os.path.expanduser('~'))
self.fileicon = self.get_icon(Gtk.STOCK_FILE)
self.diricon = self.get_icon(Gtk.STOCK_DIRECTORY)
self.icon = self.get_icon(Gtk.STOCK_FILE)

self.liststore = self.builder.get_object("liststore")
self.iconview = self.builder.get_object("iconview")
Expand All @@ -50,16 +52,15 @@ def finish_initializing(self, builder): # pylint: disable=E1002
def get_icon(self, icon):
return Gtk.IconTheme.get_default().load_icon(icon, 48, 0)

def on_iconview_item_activated(self, widget, item):
model = widget.get_model()
path = model[item][COL_PATH]
subprocess.Popen(["gnome-open", path])

def fill_store(self):
self.liststore.clear()

if self.current_directory == None:
return

for fl in os.listdir(self.current_directory):

if not fl[0] == '.':
if os.path.isdir(os.path.join(self.current_directory, fl)):
self.liststore.append([fl, self.diricon, True])
else:
self.liststore.append([fl, self.fileicon, False])
for pid in get_pids():
for file_name in get_file_names(pid):
path = '/proc/%s/fd/%s' %(pid, file_name)
self.liststore.append([path, self.icon, True])
67 changes: 67 additions & 0 deletions flashcache.py
@@ -0,0 +1,67 @@
import os
import subprocess

def get_pids():
pids = []

cat = subprocess.Popen(['ps', 'aux'],
stdout=subprocess.PIPE,
)

grep = subprocess.Popen(['grep', 'libflashplayer.so'],
stdin=cat.stdout,
stdout=subprocess.PIPE,
)

tr = subprocess.Popen(['tr', '-s', ' '],
stdin=grep.stdout,
stdout=subprocess.PIPE,
)

cut = subprocess.Popen(['cut', '-d', ' ', '-f', '2'],
stdin=tr.stdout,
stdout=subprocess.PIPE,
)

end_of_pipe = cut.stdout

for line in end_of_pipe:
pids.append(line.strip())
return pids

def get_file_names(pid):
file_names = []

path = '/proc/%s/fd/' % (pid)

if os.path.exists(path):

ls = subprocess.Popen(['ls', '-l', path],
stdout=subprocess.PIPE,
)

grep = subprocess.Popen(['grep', 'FlashXX'],
stdin=ls.stdout,
stdout=subprocess.PIPE,
)

tr = subprocess.Popen(['tr', '-s', ' '],
stdin=grep.stdout,
stdout=subprocess.PIPE,
)

cut = subprocess.Popen(['cut', '-d', ' ', '-f', '9'],
stdin=tr.stdout,
stdout=subprocess.PIPE,
)

end_of_pipe = cut.stdout

for line in end_of_pipe:
file_names.append(line.strip())

return file_names

if __name__ == '__main__':
for pid in get_pids():
print get_file_names(pid)

0 comments on commit 121014e

Please sign in to comment.