This program isn't really a solution to anything, since all file managers can mount a network drive. But I wanted to try making one, so here it is!
Code: Select all
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.6.8 on Sun Sep 7 16:38:49 2014
#
import subprocess
import wx
# begin wxGlade: dependencies
import gettext
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.combo_box_1 = wx.ComboBox(self, wx.ID_ANY, choices=[], style=wx.CB_DROPDOWN)
self.button_5 = wx.Button(self, wx.ID_ANY, _("Reload"))
self.label_1 = wx.StaticText(self, wx.ID_ANY, _("Username"), style=wx.ALIGN_CENTRE)
self.text_ctrl_1 = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_PROCESS_TAB)
self.label_2 = wx.StaticText(self, wx.ID_ANY, _("Password"), style=wx.ALIGN_CENTRE)
self.text_ctrl_2 = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_PROCESS_TAB | wx.TE_PASSWORD)
self.label_3 = wx.StaticText(self, wx.ID_ANY, _("Mount Location"))
self.text_ctrl_3 = wx.TextCtrl(self, wx.ID_ANY, _("/MEDIA/"))
self.panel_4 = wx.Panel(self, wx.ID_ANY)
self.button_4 = wx.Button(self, wx.ID_ANY, _("Connect"))
self.panel_5 = wx.Panel(self, wx.ID_ANY)
self.panel_6 = wx.Panel(self, wx.ID_ANY)
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_BUTTON, self.reload, self.button_5)
self.Bind(wx.EVT_BUTTON, self.connect, self.button_4)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle(_("frame_1"))
self.combo_box_1.SetSelection(0)
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
grid_sizer_1 = wx.GridSizer(6, 2, 0, 0)
grid_sizer_1.Add(self.combo_box_1, 0, 0, 0)
grid_sizer_1.Add(self.button_5, 0, 0, 0)
grid_sizer_1.Add(self.label_1, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.text_ctrl_1, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.label_2, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.text_ctrl_2, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.label_3, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.text_ctrl_3, 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.panel_4, 1, wx.EXPAND, 0)
grid_sizer_1.Add(self.button_4, 0, 0, 0)
grid_sizer_1.Add(self.panel_5, 1, wx.EXPAND, 0)
grid_sizer_1.Add(self.panel_6, 1, wx.EXPAND, 0)
sizer_1.Add(grid_sizer_1, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
self.Layout()
# end wxGlade
def reload(self, event): # wxGlade: MyFrame.<event_handler>
self.combo_box_1.Clear()
ips=self.makeoptions(
self.removeheaders(
self.clean(
self.run('gksu -- arp-scan --interface=wlan0 --localnet')
)
)
)
for ip in ips:
print ip
self.combo_box_1.Append(ip)
print ips
event.Skip()
def run(self, command):
print command
process=subprocess.Popen(
command.split(),
stdout=subprocess.PIPE
)
return process.communicate()[0]
def clean(self, line):
line=line.split("\n")
final=[]
for part in line:
block=part.split("\t")
if block[0]!='':
final.append(list(block))
return final
def removeheaders(self, l):
l=l[2:]
l=l[:-2]
return l
def makeoptions(self, l):
b=[]
for a in l:
b.append(str(a[0])+"/"+str(a[2]))
return b
def connect(self, event): # wxGlade: MyFrame.<event_handler>
items=dict()
items["LOCALIP"]=self.combo_box_1.GetValue().split("/")[0]
items["USERNAME"]=self.text_ctrl_1.Value
items["PASSWORD"]=self.text_ctrl_2.Value
items["SERVERNAME"]=self.text_ctrl_3.Value
self.run("gksu -- mkdir {SERVERNAME}".format(**items))
run="gksu -- mount -t cifs smb//{LOCALIP}/C {SERVERNAME} -o username={USERNAME},password={PASSWORD}".format(**items)
print run
self.run(run)
event.Skip()
# end of class MyFrame
if __name__ == "__main__":
gettext.install("app") # replace with the appropriate catalog name
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, wx.ID_ANY, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()