示例#1
0
文件: ipv6.py 项目: licshire/xnote
def get_local_ipv6_address():
    """
    This function will return your local machine's ipv6 address if it exits.
    If the local machine doesn't have a ipv6 address,then this function return None.
    This function use subprocess to execute command "ipconfig", then get the output
    and use regex to parse it ,trying to  find ipv6 address.
    """
    if xutils.is_windows():
        getIPV6_process = subprocess.Popen("ipconfig", stdout = subprocess.PIPE)
    elif xutils.is_mac():
        getIPV6_process = subprocess.Popen("ifconfig", stdout = subprocess.PIPE)
    else:
        getIPV6_process = None
    
    if not getIPV6_process:
        return None

    output = (getIPV6_process.stdout.read())

    ipv6_pattern='(([a-f0-9]{1,4}:){7}[a-f0-9]{1,4})'
    m = re.search(ipv6_pattern, str(output))
    if m is not None:
        return m.group()
    else:
        return None
示例#2
0
文件: command.py 项目: zenistzw/xnote
 def GET(self):
     path = xutils.get_argument("path")
     path = '"%s"' % path
     if xutils.is_windows():
         path = path.replace("/", "\\")
         cmd = "explorer %s" % path
     elif xutils.is_mac():
         cmd = "open %s" % path
     print(cmd)
     os.popen(cmd)
     return "<html><script>window.close()</script></html>"
示例#3
0
文件: fs.py 项目: ydx2099/xnote
    def GET(self, name):
        if name == "home":
            link_path = "./"
            if xutils.is_mac():
                link_path = os.environ['HOME']
            if xutils.is_windows():
                link_path = os.path.join(os.environ['HOMEDRIVE'],
                                         os.environ['HOMEPATH'])
        else:
            link_path = os.path.join(xconfig.DATA_DIR, name)

        link_path = os.path.abspath(link_path)
        raise web.seeother("/fs/%s" % link_path)
示例#4
0
 def POST(self):
     path = xutils.get_argument("path", "")
     # command = xutils.readfile(path)
     # subprocess和os.popen不能执行多条命令(win32)
     # subprocess在IDLE下会创建新的会话窗口,cmd下也不会创建新窗口
     # subprocess执行命令不能换行
     # os.popen可以执行系统命令
     # os.popen就是subprocess.Popen的封装
     if xutils.is_mac():
         os.system("open -a Terminal \"%s\"" % path)
         return "success"
     if xutils.is_windows():
         os.popen("start; cd \"%s\"" % path)
         return "success"
     return "failed"
示例#5
0
def watch_clipboard(ctx=None):
    global last_paste
    if xutils.is_mac():
        # MAC下面通过定时来简单实现
        info = os.popen("pbpaste").read()
        if info:
            info = info.strip()
            if info != last_paste:
                dirname = os.path.join(xconfig.LOG_DIR, "clipboard")
                fsutil.makedirs(dirname)

                fpath = get_current_log_path()
                fsutil.writeline(fpath,
                                 "\n----- %s -----" % dateutil.format_time(),
                                 "ab")
                fsutil.writeline(fpath, info, "ab")
                last_paste = info
示例#6
0
文件: command.py 项目: zenistzw/xnote
 def GET(self):
     command = xutils.get_argument("command", "")
     path    = xutils.get_argument("path", "")
     # command = xutils.readfile(path)
     # subprocess和os.popen不能执行多条命令(win32)
     # subprocess在IDLE下会创建新的会话窗口,cmd下也不会创建新窗口
     # subprocess执行命令不能换行
     # os.popen可以执行系统命令
     # os.popen就是subprocess.Popen的封装
     print(command, path)
     if command == "openTerminal":
         if xutils.is_mac():
             # TODO
             pass
         if xutils.is_windows():
             os.popen("start; cd \"%s\"" % path)
         return "success"
     if path.endswith(".bat"):
         os.popen("start %s" % path)
     else:
         os.popen(path)
     # os.popen(command)
     return "success"
示例#7
0
def get_default_shell_ext():
    if xutils.is_mac():
        return ".command"
    elif xutils.is_windows():
        return ".bat"
    return ".sh"