예제 #1
0
  def update_path(self):
    """Checks PATH variable and edits it accordingly.

    Update or repair Windows PATH. If called after setup, path will be updated.
    If called by the flag --fix_path, path will be repaired.
    """
    update = ""
    # Installed by this script
    if not find_executable("cwebp"):
      cwebp_ver, _ = CWEBP_VERSIONS.get(self.version)
      update = (os.path.join(self.cwebp_path, cwebp_ver, "bin") + os.pathsep
                + update)
    if not find_executable("cl"):
      update = (os.path.join(self.program_files, self.vs_version, "VC", "bin")
                + os.pathsep + update)

    # Installed by exe installers
    if not find_executable("cmake"):
      location = util.check_dir(self.cmake_path,
                                os.path.join(CMAKE_VERSION, "bin"), "cmake.exe")
      if not location:
        location = util.find_file(self.program_files, "cmake.exe")
        if location:
          location = os.path.dirname(location)
      if location:
        update = location + os.pathsep + update
      else:
        logging.warn("Unable to set path for CMake. Please rerun this script "
                     "with additional flag:\n\t--cmake=\\path\\to\\cmake")
    if not find_executable("java"):
      location = util.check_dir(self.java_path, "bin", "java.exe")
      if not location:
        location = util.find_file(os.path.dirname(self.program_files),
                                  "java.exe")
        if location:
          location = os.path.dirname(location)
      if location:
        update = location + os.pathsep + update
      else:
        logging.warn("Unable to set path for Java. Please rerun this script "
                     "with the additional flag:\n\t--java=\\path\\to\\java")
    if not find_executable("python"):
      location = util.check_dir(self.python_path, "files", "python.exe")
      if not location:
        location = util.find_file(os.path.dirname(self.program_files),
                                  "python.exe")
        if location:
          location = os.path.dirname(location)
      if location:
        update = location + os.pathsep + update
      else:
        logging.warn("Unable to set path for Python. Please rerun this script "
                     "with the additional flag:\n\t--python=\\path\\to\\python")
    self.path_update = update
    self.bash_profile_changed = True
예제 #2
0
  def windows_install_java(self):
    """Check for and install Java.

    Downloading the jdk installer can't be done through python, or equivalent
    bash commands due to some javascript on the download site. It instead has
    to be through the users default browser.

    Raises:
      WebbrowserFailedError: If the link to Java JDK could not be opened in
          the user's default browser.
      InstallInterruptError: If the user cancels the wait for installation of
          Java JDK.
    """
    if find_executable("java"):
      logging.info("Java already installed.")
      return
    # Since installing Java is annoying, we want to make doubly sure the user
    # doesn't have it already.
    location = util.find_file(PROGRAM_FILES, "java.exe")
    if not location and self.program_files == PROGRAM_FILES_X86:
      # In case the user has installed the 32 bit version on a 64 bit machine
      location = util.find_file(PROGRAM_FILES_X86, "java.exe")
    if location:
      logging.info("Java already installed at " + location + ".")
      self.java_path = os.path.dirname(location)
      return
    logging.warn("Java not installed. Please accept the terms and conditions, "
                 "and download:\n\t" + JAVA_VERSIONS.get(self.version) +
                 "\nOnce download is complete, double click the exe and follow "
                 "installation instructions.")
    # Java JDK can't be installed without the user accepting the terms and
    # conditions, which can only be done in their browser
    logging.warn("Java not installed. Opening browser...")
    if not util.open_link(JAVA_URL, "Java JDK"):
      raise common.WebbrowserFailedError("Java JDK", JAVA_URL)
    if not util.wait_for_installation("java.exe", search=True,
                                      basedir=PROGRAM_FILES):
      raise common.InstallInterruptError("Java JDK")
    logging.info("Java successfully installed.")
예제 #3
0
 def get_default_start(self):
     try:
         file_path = '%s/Content/AppContents/app_info.json' % (
             config.const_client_root())
         if os.path.exists(file_path):
             with open(file_path, 'r', encoding='utf-8') as data_file:
                 str_content = data_file.read()
                 app_list = json.loads(str_content)
                 for app in app_list:
                     if app['isStart'] == True:
                         f = util.find_file(
                             app['startPath'], '%s/Content/AppContents/%s' %
                             (config.const_client_root(), str(
                                 app['appId'])))
                         finnal = f.replace(config.const_client_root(), '')
                         config.current_app_id = app['appId']
                         return app['appId'], '%s%s' % (
                             config.const_client_web_server_root, finnal)
             return None
         else:
             return None
     except Exception as err:
         print(err)
예제 #4
0
    def run(data, skip_on_failure=False):
        program_dir_abs = data["program_dir_abs"]
        lines_of_code = data["lines_of_code"]
        use_cmake = data["use_cmake"]
        use_make = data["use_make"]
        excluded_paths = data["excluded_paths"]
        compilation_status = False

        if use_cmake:
            program_dir_abs += "/" + strings.INFER_BUILD_DIR_NAME
            compilation_status = InferTool.compile_with_cmake(
                program_dir_abs, excluded_paths)
        elif use_make:
            compilation_status = InferTool.compile_with_make(
                program_dir_abs, excluded_paths)

        if not compilation_status:
            return [0], "", False

        # TODO: maybe fix the error handling differently (not by the --keep-going flag)
        infer_analyze = [TOOLS.INFER.exe_name, "analyze", "--keep-going"]

        try:
            subprocess.check_output(infer_analyze,
                                    cwd=program_dir_abs,
                                    universal_newlines=True,
                                    stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as error:
            print(
                strings.COMPILATION_CRASHED.format(error.returncode,
                                                   error.output))
            template = "An exception of type {0} occurred. Arguments:\n{1!r}"
            message = template.format(type(error).__name__, error.args)
            print(message)
            if not skip_on_failure:
                raise
            return [0], "", False
        except Exception:  # catch the rest and exclude the analysis tool from the score
            if not skip_on_failure:
                raise
            return [0], "", False

        infer_out_path = util.find_file(
            program_dir_abs,
            strings.INFER_OUTPUT_FILE_NAME,
            directory=strings.INFER_OUTPUT_DIR_NAME)
        if infer_out_path == "":
            return [0], "Could not find {}".format(
                strings.INFER_OUTPUT_FILE_NAME), False

        file_out, warnings, warning_num = InferTool.get_warnings_from_output(
            infer_out_path)
        util.write_into_file_string(strings.RESULTS_FILENAME_INFER, file_out)

        infer_warning_rate = warning_num / lines_of_code
        score = scoring.calculate_infer_score_absolute(infer_warning_rate)

        log = strings.RUN_INFER_ANALYSIS_HEADER + "\n"
        log += warnings + "\n"
        # TODO: make and print filename to user
        log += "Weighted Infer warning rate: {} ({}/{})".format(
            warning_num / lines_of_code, warning_num, lines_of_code) + "\n"
        log += scoring.get_score_string(score, 'Infer') + "\n"

        return [score], log, True
예제 #5
0
def main() -> None:
    transactions = process(
        find_file("/Users/seanscott/Downloads/", "DFS-Search-", ".csv"))
    transactions.date_sort()
    transactions.glob_small_amounts()
    print(transactions)
예제 #6
0
rsds
  netcdf units: Wm^-2    multiply by 86,400 divide by 1,000,000
  swat file has: MJ / day
"""
import datetime
import numpy as np
from scipy import interpolate
import util
import sys

model = sys.argv[1]
scenario = sys.argv[2]
MYDIR = "/tera13/akrherz/cmip3_monthly"

nc_20c = util.find_file(model, '20c3m', 'rsds')
nc_a1b = util.find_file(model, scenario, 'rsds')

lats = nc_20c.variables['lat'][:]
lons = nc_20c.variables['lon'][:]

# print 'HADCM3 HACK HERE!'
idx1_20c = util.find_time_idx(nc_20c, datetime.datetime(1981, 1, 1))
idx2_20c = util.find_time_idx(nc_20c, datetime.datetime(1999, 12, 1)) + 1
idx1_a1b = util.find_time_idx(nc_a1b, datetime.datetime(2046, 1, 1))
idx2_a1b = util.find_time_idx(nc_a1b, datetime.datetime(2064, 12, 1)) + 1

rsds_20c = nc_20c.variables['rsds'][idx1_20c:idx2_20c, :, :]
rsds_a1b = nc_a1b.variables['rsds'][idx1_a1b:idx2_a1b, :, :]

jan = np.average(rsds_a1b[::12, :, :], 0) - np.average(rsds_20c[::12, :, :], 0)
예제 #7
0
 1981 thru 2000

rsds
  netcdf units: Wm^-2    multiply by 86,400 divide by 1,000,000
  swat file has: MJ / day
"""
import datetime
import numpy
from scipy import interpolate
import util
import sys

model = sys.argv[1]
MYDIR = "/tera13/akrherz/cmip3_monthly"

nc_20c_uas = util.find_file(model, '20c3m', 'uas')
nc_20c_vas = util.find_file(model, '20c3m', 'vas')
nc_a1b_uas = util.find_file(model, 'sresa1b', 'uas')
nc_a1b_vas = util.find_file(model, 'sresa1b', 'vas')

lats = nc_20c_uas.variables['lat'][:]
lons = nc_20c_uas.variables['lon'][:]

idx1_20c = util.find_time_idx(nc_20c_uas, datetime.datetime(1981,1,1) )
idx2_20c = util.find_time_idx(nc_20c_uas, datetime.datetime(1999,12,1) ) + 1
idx1_a1b = util.find_time_idx(nc_a1b_uas, datetime.datetime(2046,1,1) )
idx2_a1b = util.find_time_idx(nc_a1b_uas, datetime.datetime(2064,12,1) ) + 1

uas_20c = nc_20c_uas.variables['uas'][idx1_20c:idx2_20c,:,:]
vas_20c = nc_20c_vas.variables['vas'][idx1_20c:idx2_20c,:,:]
wnd_20c = numpy.sqrt( uas_20c ** 2 + vas_20c ** 2 )
예제 #8
0
def main():
    transactions: TransactionList = process(find_file("/Users/seanscott/Downloads/", "", "_transaction_download.csv"))
    transactions.date_sort()
    transactions.glob_small_amounts()
    print(transactions)
예제 #9
0
(v)  For each month in the composite annual cycles, subtract Td for current
climate from Td for future climate to get the delta.  Then add this to the
observed annual cycle of Td.


"""
import datetime
import numpy as np
from scipy import interpolate
import util
import sys

model = sys.argv[1]
MYDIR = "/tera13/akrherz/cmip3_monthly"

nc_20c_ps = util.find_file(model, '20c3m', 'ps')
nc_20c_huss = util.find_file(model, '20c3m', 'huss')
nc_a1b_ps = util.find_file(model, 'sresa1b', 'ps')
nc_a1b_huss = util.find_file(model, 'sresa1b', 'huss')

lats = nc_20c_ps.variables['lat'][:]
lons = nc_20c_ps.variables['lon'][:]

idx1_20c = util.find_time_idx(nc_20c_ps, datetime.datetime(1981, 1, 1))
idx2_20c = util.find_time_idx(nc_20c_ps, datetime.datetime(1999, 12, 1)) + 1
idx1_a1b = util.find_time_idx(nc_a1b_ps, datetime.datetime(2046, 1, 1))
idx2_a1b = util.find_time_idx(nc_a1b_ps, datetime.datetime(2064, 12, 1)) + 1

ps_20c = nc_20c_ps.variables['ps'][idx1_20c:idx2_20c, :, :] / 100.0
huss_20c = nc_20c_huss.variables['huss'][idx1_20c:idx2_20c, :, :]
r_20c = huss_20c / (1 - huss_20c)
예제 #10
0
파일: config.py 프로젝트: jaheba/dfb-tools
schema = ''

host = ''
port = None
user = ''
password = ''

import util
import os

_config = os.environ.get('SOCA_CONFIG') or util.find_file('.socarc')

if _config:
    locals().update(util.read_config(_config))