From ae48b086b58f5cb8491d05ff7a9e38e42470dbd4 Mon Sep 17 00:00:00 2001 From: Giorgos Korfiatis <gkorf@grnet.gr> Date: Wed, 17 Jun 2015 11:38:37 +0300 Subject: [PATCH] win updated --- agkyra/protocol.py | 13 +++++++++---- agkyra/syncer/localfs_client.py | 33 +++++++++++++++++---------------- agkyra/syncer/pithos_client.py | 2 +- agkyra/syncer/utils.py | 16 +++++++++++++--- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/agkyra/protocol.py b/agkyra/protocol.py index 1d208da..60348a7 100644 --- a/agkyra/protocol.py +++ b/agkyra/protocol.py @@ -24,6 +24,7 @@ import time import os import json import logging +import subprocess from agkyra.syncer import ( syncer, setup, pithos_client, localfs_client, messaging, utils) from agkyra.config import AgkyraConfig, AGKYRA_DIR @@ -704,7 +705,11 @@ class WebSocketProtocol(WebSocket): def launch_server(): """Launch the server in a separate process""" LOG.info('Start SessionHelper session') - pid = os.fork() - if not pid: - server_path = os.path.join(CURPATH, 'scripts', 'server.py') - os.execlp("python", "python", server_path) + server_path = os.path.join(CURPATH, 'scripts', 'server.py') + if utils.iswin(): + subprocess.Popen(["pythonw.exe", server_path], + close_fds=True) + else: + pid = os.fork() + if not pid: + os.execlp("python", "python", server_path) diff --git a/agkyra/syncer/localfs_client.py b/agkyra/syncer/localfs_client.py index 37711ae..9398a9d 100644 --- a/agkyra/syncer/localfs_client.py +++ b/agkyra/syncer/localfs_client.py @@ -21,6 +21,7 @@ import psutil import time import filecmp import shutil +import errno from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler @@ -39,11 +40,6 @@ LOCAL_MISSING = 3 LOCAL_SOFTLINK = 4 LOCAL_OTHER = 5 -OS_FILE_EXISTS = 17 -OS_NOT_A_DIR = 20 -OS_NO_FILE_OR_DIR = 2 -OS_IS_DIR = 21 - DEFAULT_MTIME_PRECISION = 1e-4 exclude_regexes = ["\.#", "\.~", "~\$", "~.*\.tmp$", "\..*\.swp$"] @@ -55,15 +51,16 @@ class DirMissing(BaseException): def link_file(src, dest): + cmd = os.rename if utils.iswin() else os.link try: - os.link(src, dest) + cmd(src, dest) except OSError as e: - if e.errno == OS_FILE_EXISTS: + if e.errno == errno.EEXIST: raise common.ConflictError("Cannot link, '%s' exists." % dest) - if e.errno == OS_NOT_A_DIR: + if e.errno in [errno.ENOTDIR, errno.EINVAL]: raise common.ConflictError( "Cannot link, missing path for '%s'." % dest) - if e.errno == OS_NO_FILE_OR_DIR: + if e.errno == errno.ENOENT: raise DirMissing() @@ -71,9 +68,9 @@ def make_dirs(path): try: os.makedirs(path) except OSError as e: - if e.errno == OS_FILE_EXISTS and os.path.isdir(path): + if e.errno == errno.EEXIST and os.path.isdir(path): return - if e.errno in [OS_FILE_EXISTS, OS_NOT_A_DIR]: + if e.errno in [errno.EEXIST, errno.ENOTDIR, errno.ENOENT]: raise common.ConflictError("Cannot make dir '%s'." % path) raise @@ -118,7 +115,7 @@ def get_orig_name(filename): def mk_stash_name(filename): - tstamp = datetime.datetime.now().isoformat() + tstamp = utils.str_time_stamp() orig = get_orig_name(filename) return orig + '_' + tstamp + '_' + utils.NODE @@ -132,7 +129,7 @@ def files_equal(f1, f2): try: return filecmp.cmp(f1, f2, shallow=False) except OSError as e: - if e.errno in [OS_NO_FILE_OR_DIR, OS_NOT_A_DIR]: + if e.errno in [errno.ENOENT, errno.ENOTDIR]: return False raise @@ -170,7 +167,7 @@ def stat_file(path): try: return os.lstat(path) except OSError as e: - if e.errno in [OS_NO_FILE_OR_DIR, OS_NOT_A_DIR]: + if e.errno in [errno.ENOENT, errno.ENOTDIR]: return None raise @@ -299,10 +296,14 @@ class LocalfsTargetHandle(object): logger.debug("Hiding file '%s' to '%s'" % (fspath, hidden_path)) except OSError as e: - if e.errno in [OS_NO_FILE_OR_DIR, OS_NOT_A_DIR]: + if e.errno in [errno.ENOENT, errno.ENOTDIR]: self.unregister_hidden_name(hidden_filename) logger.debug("File '%s' does not exist" % fspath) return + elif e.errno == errno.EACCES: + self.unregister_hidden_name(hidden_filename) + raise common.BusyError("File '%' is open. Undoing." % + hidden_path) else: raise e @@ -434,7 +435,7 @@ class LocalfsSourceHandle(object): try: shutil.copy2(fspath, stage_path) except IOError as e: - if e.errno in [OS_NO_FILE_OR_DIR, OS_IS_DIR]: + if e.errno in [errno.ENOENT, errno.EISDIR]: logger.debug("Source is not a regular file: '%s'" % fspath) self.unregister_stage_name(stage_filename) return diff --git a/agkyra/syncer/pithos_client.py b/agkyra/syncer/pithos_client.py index 0f18296..5e23cae 100644 --- a/agkyra/syncer/pithos_client.py +++ b/agkyra/syncer/pithos_client.py @@ -99,7 +99,7 @@ class PithosSourceHandle(object): def register_fetch_name(self, filename): db = self.get_db() f = utils.hash_string(filename) + "_" + \ - utils.time_stamp() + utils.str_time_stamp() fetch_name = utils.join_path(self.cache_fetch_name, f) self.fetch_name = fetch_name db.insert_cachename(fetch_name, self.SIGNATURE, filename) diff --git a/agkyra/syncer/utils.py b/agkyra/syncer/utils.py index 8538597..462d123 100644 --- a/agkyra/syncer/utils.py +++ b/agkyra/syncer/utils.py @@ -30,6 +30,13 @@ ENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding() PLATFORM = sys.platform NODE = platform.node() +def iswin(): + return PLATFORM.startswith("win") + + +def islinux(): + return PLATFORM.startswith("linux") + def to_local_sep(filename): return filename.replace(OBJECT_DIRSEP, os.path.sep) @@ -79,13 +86,16 @@ def hash_string(s): def time_stamp(): - return datetime.datetime.now().strftime("%s.%f") + return datetime.datetime.now() + + +def str_time_stamp(): + return time_stamp().isoformat().replace(':', '.') def younger_than(tstamp, seconds): now = datetime.datetime.now() - ts = datetime.datetime.fromtimestamp(int(float(tstamp))) - delta = now - ts + delta = now - tstamp return delta < datetime.timedelta(seconds=seconds) -- GitLab