Commit dd9ed14c by Bach Dániel

fix mount_store

parent 05b2e754
...@@ -41,12 +41,6 @@ mount_template_linux = ( ...@@ -41,12 +41,6 @@ mount_template_linux = (
'//%(host)s/%(username)s %(dir)s cifs username=%(username)s' '//%(host)s/%(username)s %(dir)s cifs username=%(username)s'
',password=%(password)s,iocharset=utf8,uid=cloud 0 0\n') ',password=%(password)s,iocharset=utf8,uid=cloud 0 0\n')
mount_template_windows = (
'net use * /delete /yes\r\n'
'timeout 5\r\n'
'net use z: \\%(host)s\\%(username)s "%(password)s" '
'/user:%(username)s\r\n')
system = platform.system() system = platform.system()
distros = {'Scientific Linux': 'rhel', distros = {'Scientific Linux': 'rhel',
...@@ -171,9 +165,11 @@ class Context(object): ...@@ -171,9 +165,11 @@ class Context(object):
subprocess.call('mount -a', shell=True) subprocess.call('mount -a', shell=True)
elif system == 'Windows': elif system == 'Windows':
with open(r'c:\Windows\System32\Repl\Import\Scripts\%s.bat' import notify
% username, 'w') as f: url = 'cifs://%s:%s@%s/%s' % (username, password, host, username)
f.write(mount_template_windows % data) for c in notify.clients:
logger.debug("sending url %s to client %s", url, unicode(c))
c.sendLine(url.encode())
@staticmethod @staticmethod
def get_keys(): def get_keys():
......
...@@ -14,6 +14,7 @@ import os ...@@ -14,6 +14,7 @@ import os
import platform import platform
import subprocess import subprocess
import urllib2 import urllib2
from urlparse import urlsplit
logger = logging.getLogger() logger = logging.getLogger()
logger.debug("notify imported") logger.debug("notify imported")
...@@ -127,6 +128,15 @@ def open_in_browser(url): ...@@ -127,6 +128,15 @@ def open_in_browser(url):
webbrowser.open(url, new=2, autoraise=True) webbrowser.open(url, new=2, autoraise=True)
def mount_smb(url):
data = urlsplit(url)
share = data.path.lstrip('/')
subprocess.call(('net', 'use', 'Z:', '/delete'))
subprocess.check_output((
'net', 'use', 'Z:', r'\\%s\%s' % (data.hostname, share),
data.password, '/user:%s' % data.username, '/PERSISTENT:YES'))
def file_already_exists(name, mode=0o644): def file_already_exists(name, mode=0o644):
"""Return whether file already exists, create it if not. """Return whether file already exists, create it if not.
...@@ -201,7 +211,10 @@ if win: ...@@ -201,7 +211,10 @@ if win:
def lineReceived(self, line): def lineReceived(self, line):
print "received", line print "received", line
open_in_browser(line) if line.startswith('cifs://'):
mount_smb(line)
else:
open_in_browser(line)
class SubFactory(protocol.ReconnectingClientFactory): class SubFactory(protocol.ReconnectingClientFactory):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment