Ejemplo n.º 1
0
    def readlinkWindows(path):
        reparse_point_handle = CreateFileW(
            path, 0, 0, None, OPEN_EXISTING,
            FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, None)
        if reparse_point_handle == INVALID_HANDLE_VALUE:
            from pygcam.log import getLogger
            _logger = getLogger(__name__)
            _logger.info("Can't readlink: %s", path)
            raise ctypes.WinError()

        target_buffer = ctypes.c_buffer(MAXIMUM_REPARSE_DATA_BUFFER_SIZE)
        n_bytes_returned = DWORD()
        io_result = DeviceIoControl(reparse_point_handle,
                                    FSCTL_GET_REPARSE_POINT, None, 0,
                                    target_buffer, len(target_buffer),
                                    ctypes.byref(n_bytes_returned), None)
        CloseHandle(reparse_point_handle)
        if not io_result:
            raise ctypes.WinError()

        rdb = REPARSE_DATA_BUFFER.from_buffer(target_buffer)
        if rdb.ReparseTag == IO_REPARSE_TAG_SYMLINK:
            return rdb.SymbolicLinkReparseBuffer.PrintName
        elif rdb.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT:
            return rdb.MountPointReparseBuffer.PrintName

        raise ValueError("not a link")
Ejemplo n.º 2
0
    def symlinkWindows(src, dst):
        src = src.replace('/', '\\')
        dst = dst.replace('/', '\\')

        if samefileWindows(src, dst):
            raise PygcamException(
                "Attempted to create symlink loop from '%s' to '%s' (same file)"
                % (dst, src))

        csl = ctypes.windll.kernel32.CreateSymbolicLinkW
        csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
        csl.restype = ctypes.c_ubyte

        # links to files and dir differ in Windows
        flags = 1 if os.path.isdir(src) else 0

        try:
            if csl(dst, src, flags) == 0:
                raise ctypes.WinError()
        except Exception as e:
            from pygcam.log import getLogger
            _logger = getLogger(__name__)

            if getParamAsBoolean('GCAM.SymlinkWarning'):
                _logger.error('''
  ============================================================================================================
  WARNING: The current user does not have permission to create symbolic links, forcing pygcam to copy rather
  than symlink files. This uses much more file space than using symlinks, but it works.  To use pygcam more
  efficiently, ask your System Administrator to give you permission to Create Symbol Links (using gpedit.msc)

  See http://superuser.com/questions/104845/permission-to-make-symbolic-links-in-windows-7 for more info.

  Set "GCAM.SymlinkWarning = False" in ~/.pygcam.cfg to suppress this message.
  ============================================================================================================
  ''')
            raise PygcamException("Failed to create symlink '%s' to '%s': %s" %
                                  (dst, src, e))
Ejemplo n.º 3
0
from __future__ import print_function
import subprocess as subp
import time

from pygcam.log import getLogger
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, Event

_logger = getLogger(__name__)


class Terminal(object):

    counter = 0  # to create unique ids

    def __init__(self, updateSeconds=2, toConsole=False):
        self.status = None
        self.proc = None
        self.page = None
        self.queue = None
        self.toConsole = toConsole

        self.counter += 1
        self.intervalId = intervalId = 'interval-%d' % self.counter
        self.terminalId = terminalId = 'terminal'  # 'terminal-%d' % self.counter
        self.buttonId = buttonId = 'button-%d' % self.counter

        self.running = False
        self.ms = 1000 * updateSeconds
        self.text = ''
Ejemplo n.º 4
0
#
# A "WriteFunc" is called after substituting parameter values, before
# writing modified files, per Monte Carlo trial.
#
import pandas as pd

from pygcam.config import getParam
from pygcam.utils import pathjoin
from pygcam.log import getLogger
#from pygcam.error import SetupException
from pygcam.xmlEditor import xmlEdit
from pygcam.XMLFile import McsValues

# unique name so log level is configurable in .pygcam.cfg
_logger = getLogger('ord.writeFuncs')

# TBD: Pass as kwargs to writeFuncs; need to update API docs
GROUP = ''  # directories do not include group name
BASELINE = 'mcs'

# Strategy
#
# - Allow config file itself to have a write func? Nah, need a per-trial version.
# - Copy config.xml to "exe" dir and modify it as the scenarios.xml file would have done.
# - Modify project.xml to call "gcam" step with "-C config.xml" so it takes it from exe dir.
#
# - Would it work as <InputFile name="../local-xml/base/config.xml"> ?
#   Might need special tag like <InputFile name="__config__"> or a new tag,
#   <ConfigFile>
#       <WriteFunc>writeFuncs.configure</WriteFunc>
#   </ConfigFile>