Ejemplo n.º 1
0
    def cwd(self, remote_dir):
        if remote_dir is None or remote_dir == "" or remote_dir == "/":
            lastFile = os.environ["SCRAP_DIR"] + "/oli_buybacks.last"
            try:
                lastDataMd5 = cPickle.load(open(lastFile, 'rb'))
            except IOError:
                lastDataMd5 = None
            # Grab data
            data = _getBuybacks2()
            if data is None:
                self._remote_dir = None
                util.error("Failed to load web page")
                return

            if len(data) == 0:
                util.error(
                    "Failed to read any data. Go and check if the parser is still valid"
                )

            m = hashlib.md5()
            m.update(str(data))
            dataMd5 = m.digest()
            if (lastDataMd5 is not None and lastDataMd5 == dataMd5):
                self._remote_dir = None
                return
            # Save data to temp dir
            tempdir = util.tmpdir()
            f = open(
                "%s/%s.txt" %
                (tempdir, datetime.datetime.now().strftime("%Y%m%d")), "w")
            for row in data:
                try:
                    f.write(("\t".join(row) + "\n").encode('ascii', 'ignore'))
                except:
                    print row
                    raise
            f.close()
            self._remote_dir = tempdir
            self.__tmpDirs.append(tempdir)
            cPickle.dump(dataMd5, open(lastFile, 'wb'))
        else:
            # Grab data
            data = _getBuybacks2(remote_dir)
            if data is None:
                self._remote_dir = None
                return
            # Save data to temp dir
            tempdir = util.tmpdir()
            f = open(
                "%s/%s.txt" %
                (tempdir, datetime.datetime.now().strftime("%Y%m%d")), "w")
            for row in data:
                try:
                    f.write(("\t".join(row) + "\n").encode('ascii', 'ignore'))
                except:
                    print row
                    raise
            f.close()
            self._remote_dir = tempdir
            self.__tmpDirs.append(tempdir)
Ejemplo n.º 2
0
def getLogs(day, pattern):
    tmpDir = util.tmpdir()
    tmpFilepath = tmpDir + "/temp.temp"
    data = []
    #parse the config file to get the exec servers
    cfg = config.load_trade_config(os.environ['CONFIG_DIR'] + '/exec.conf')
    for host, port in cfg["servers"]:
        src = SFTPSource(host, "ase", None)
        try:
            if day <= "20110802":
                #get the exec number
                m = re.match(r"exectrade(\d).jc", host)
                if m is None:
                    raise Exception(
                        "Failed to parse host name to get its number for historical data. host={}"
                        .format(host))
                else:
                    number = m.group(1)
                remoteDir = os.path.join(
                    "/spare/local/guillotine_old.20110802", "log",
                    "rts1_{}.{}".format(number, day))
            else:
                remoteDir = os.path.join(os.environ["EXEC_ROOT_DIR"], "log",
                                         day)
            src.cwd(remoteDir)
            files = src.list(pattern)
            if len(files) != 1:
                raise Exception("Found {} {} files in {}:{}".format(
                    len(files), pattern, host, remoteDir))
            src.copy(remoteDir + "/" + files[0][0], tmpFilepath)
            with open(tmpFilepath, "r") as file:
                for line in file:
                    data.append(line.strip())
        except Exception, e:
            util.warning(str(e))
Ejemplo n.º 3
0
 def __init__(self):
     # Save data to temp dir
     tempdir = util.tmpdir()
     filename = "shortint.%s.txt" % datetime.date.today().strftime("%Y%m%d")
     os.system("wget -q http://shortsqueeze.com/userftp106/%s -O%s/%s" %
               (filename, tempdir, filename))
     if os.path.getsize('%s/%s' % (tempdir, filename)) == 0:
         os.remove('%s/%s' % (tempdir, filename))
     self._remote_dir = tempdir
Ejemplo n.º 4
0
	def tmpdir(self, cmd, files, code):
		return util.tmpdir(cmd, files, self.filename, code)
Ejemplo n.º 5
0
 def tmpdir(self, cmd, files, code):
     return util.tmpdir(cmd, files, self.filename, code)
Ejemplo n.º 6
0
import shutil
import os

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print "Use as compare_calcres.py <newfile> <oldfile>"
        sys.exit(1)

    util.set_silent()
    new2oldMappings = util.loadDictFromFile(os.environ["CONFIG_DIR"] +
                                            "/calcres.translation")

    newCalcresFile = sys.argv[1]
    oldCalcresFile = sys.argv[2]

    tmpdir = util.tmpdir()
    #load new calcres
    newC = {}
    calcresSummary.calcresStats(newCalcresFile, tmpdir + "/new.txt", False)
    with open(tmpdir + "/new.txt", "r") as file:
        for line in file:
            if len(line) <= 1: continue
            tokens = line.strip().split("|")
            attr = tokens[0]
            size = int(tokens[1])

            mean = float(tokens[2]) if tokens[2] != "NA" else float('nan')
            std = float(tokens[3]) if tokens[3] != "NA" else float('nan')
            mmin = float(tokens[4]) if tokens[4] != "NA" else float('nan')
            mmax = float(tokens[5]) if tokens[5] != "NA" else float('nan')
            newC[attr] = (size, mean, std, mmin, mmax)
Ejemplo n.º 7
0
def test_make():
    dest = path(tmpdir()) / 'Nanpy'
    FIRMWARE.copytree(dest)

    p = EasyProcess('make size BOARD=uno', cwd=dest).call()
    eq_(p.return_code, 0)
Ejemplo n.º 8
0
def test_make():
    dest = tmpdir() + '/Nanpy'
    shutil.copytree(FIRMWARE, dest)
    p = EasyProcess('make size BOARD=uno', cwd=dest).call()
    eq_(p.return_code, 0)