コード例 #1
0
def bindiff(file1,file2,returnfulldiff=False):
    """ binary compare 2 files
    :param file1 :string
    :param file2 :string
    :param returnfulldiff : boolean, if False func returns True/False otherwise full diff
    rtype:boolean or list of string
    """
    import sys
    from types import BooleanType
    from misc_utils_process import process_start,process_get_stdout
    from misc_utils import os_file_exists
    
    assert os_file_exists(file1),file1
    assert os_file_exists(file2),file2
    assert isinstance(returnfulldiff,BooleanType)
    
    if sys.platform == "win32":
        cmd = ['fc.exe','/B',file1,file2]
        p = process_start(cmd)
        diff_result = process_get_stdout(p)
        
        if diff_result.split("\n")[1].startswith("FC: no differences encountered"):
            return True
    
        if returnfulldiff:
            return diff_result.split("\n")
        return False
コード例 #2
0
    def setUp(self):
        self.tmp_module1 = path.join(TESTDIR, "tmp_module.py")
        self.tmp_module2 = path.join(TESTDIR, "tmp_module2.py")
        self.tmp_module3 = path.join(TESTDIR, "tmp_module3.py")

        assert (os_file_exists(self.tmp_module1))
        assert (os_file_exists(self.tmp_module2))
        assert (os_file_exists(self.tmp_module3))
コード例 #3
0
ファイル: test_utils.py プロジェクト: burtnolej/quadviewer
def testrunner(rootdir="C:\\Users\\burtnolej\\Development",
               inc_testcase=[],inc_module=[],exc_module=[],dryrun=False):
    
    assert isinstance(inc_testcase,ListType), inc_testcase
    assert isinstance(inc_module,ListType), inc_module
    assert isinstance(dryrun,BooleanType), dryrun
    assert os_file_exists(rootdir),rootdir
        
    suite = unittest.TestSuite()
    testsummary = {}

    for root,cwd,files in walk(rootdir):
        for file in files:
            if file.startswith("test_") and splitext(file)[1] == ".py":
                if inc_module != [] and file not in inc_module: continue
                if exc_module != [] and file in exc_module: continue
                _module = load_module(join(root,file))  
                for item in dir(_module):
                    if item.startswith('Test'):
                        if inc_testcase != [] and item not in inc_testcase: continue
                        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(getattr(_module,item)))
                        add2dict(testsummary,file,item)    
    if dryrun:
        pprint(testsummary)
    else:
        results = unittest.TextTestRunner(verbosity=3,buffer=True).run(suite)
        pprint(summarise_testresults(results))
コード例 #4
0
    def test_(self):
        self.dtr_tcx.load_page(self.baseurl)
        self.dtr_tcx.login(self.xpaths, self.uname, self.pword)

        self.xpaths[
            'rideListName'] = "//div[contains(@class,'ride-list-name')]"

        rides = self.dtr_tcx.get_rides(1)

        self.xpaths['downloadRide'] = "//a[contains(@class,'downloadRide')]"
        self.xpaths['rideListDate'] = "//p[contains(@class,'gray-light')]/span"
        self.xpaths['rideTitle'] = "//h1[contains(@class,'mb0')]/a"
        self.xpaths['notes'] = "//textarea[contains(@class,'form-control')]"

        self.dtr_tcx.download_rides(rides, self.xpaths)

        # get the file name that would have been downloaded
        # check it has been downloaded and then delete it
        self.dtr_tcx.mydriver.get(rides[0])

        ride_file_name = self.dtr_tcx._get_ride_file_name(
            rides[0], self.xpaths)

        self.assertTrue(os_file_exists(DOWNLOAD_DIR + "\\" + ride_file_name))

        os.remove(DOWNLOAD_DIR + "\\" + ride_file_name)
コード例 #5
0
    def download_rides(self, rides, xpaths=xpaths):
        for ride in rides:
            try:
                self.mydriver.get(ride)
            except Exception, e:
                log.log(PRIORITY.FAILURE,
                        msg="cannot load page for [" + ride + "] [" +
                        e.message + "]")
                continue
            else:
                log.log(PRIORITY.SUCCESS, msg="loaded page for [" + ride + "]")

            ride_file_name = self._get_ride_file_name(ride, xpaths=xpaths)

            if os_file_exists(DOWNLOAD_DIR + "\\" + ride_file_name) == True:
                #print "skipping",ride_file_name,"already downloaded, exitting"
                log.log(PRIORITY.INFO,
                        msg="skipping, already downloaded [" + ride_file_name +
                        "] exitting")
                exit()
            else:
                try:
                    self._click_download(xpaths=xpaths)
                    try:
                        self._persist_ride_meta(xpaths=xpaths)
                    except Exception, e:
                        log.log(PRIORITY.FAILURE,
                                msg="failed to download meta  [" +
                                ride_file_name + "] [" + e.message + "]")
                    else:
コード例 #6
0
ファイル: image_utils.py プロジェクト: burtnolej/quadviewer
    def create_image_file(self, labels, **kw):
        if not kw.has_key('convert_exec'):
            convert_exec = "convert"
        else:
            convert_exec = kw['convert_exec']
            log.log(PRIORITY.INFO,
                    msg="convert command being set to [" + convert_exec + "]")

        if not kw.has_key('overwrite'):
            kw['overwrite'] = False
            log.log(PRIORITY.INFO, msg="overwrite not set")

        if not isinstance(labels, list):
            labels = [labels]

        self.outputfiles = []
        self.labels = labels
        self.outputdirname = ImageCreate._getoutputdirname()

        for lbl in self.labels:
            cmd = [convert_exec, '-verbose']
            outputfilename = get_gif_filename(self.outputdirname, lbl, kw)

            if os_file_exists(
                    outputfilename) == False or kw['overwrite'] == True:

                # settings go before the input label/file
                for s in settings:
                    if kw.has_key(s):
                        cmd = cmd + ["-" + s, str(kw[s])]

                cmd.append(labelstr_get(lbl))

                # image operators come afterwards
                for im in image_operator:
                    if kw.has_key(im):
                        cmd = cmd + ["-" + im, str(kw[im])]

                cmd.append(outputfilename)
                p = process_start(cmd)
                status = parse_convert_stdout(p, lbl)

                if status[0] == 0:
                    log.log(PRIORITY.INFO,
                            msg="create_image=" + outputfilename)
                else:
                    log.log(PRIORITY.FAILURE,
                            msg="status=" + ",".join(map(str, status)))
                    raise Exception("ImageCreate failure", status)

            else:
                log.log(PRIORITY.INFO, msg="reused_image=" + outputfilename)

            self.outputfiles.append(outputfilename)

        return (self.outputfiles)
コード例 #7
0
def os_dir_delete(dirpath,dirname=None,treedel=False):
    """ deletes a directory
    :param dirpath: string, path to directory
    :param optional dirname: string, name of dir, if not provides its assumed that dirpath is the fullpath
    :param treedel: boolean, recursively delete files in dir or not
    """

    assert os_file_exists(dirpath) or os_file_exists(os.path.join(dirpath,dirname))
    from os.path import join
    from os import mkdir, rmdir
    from shutil import rmtree
    
    if dirname != None:
        dirpath= join(dirpath,dirname)
        
    if not treedel:
        rmdir(dirpath)
    else:
        rmtree(dirpath)
コード例 #8
0
ファイル: image_utils.py プロジェクト: burtnolej/hungrycrayon
    def create_image_file(self,labels, **kw):

        if not kw.has_key('overwrite'):
            kw['overwrite'] = False
            
        if not isinstance(labels,list):
            labels = [labels]
        
        self.outputfiles = []
        self.labels = labels
        self.outputdirname = "ic_"+now()
        cwd = getcwd()
        
        try:
            mkdir(ospathjoin(cwd,self.outputdirname))
        except OSError: # directory exists
            pass
        
        self.log.log(self,3,"mkdir="+self.outputdirname)

        for lbl in self.labels:
            
            cmd = ['convert','-verbose']

            outputfilename = get_gif_filename(self.outputdirname,lbl,kw)
            #filename = lbl + "-" + "-".join(map(str,kw.values())) + ".gif"  
            #outputfilename = ospathjoin(self.outputdirname,filename)
            
            if os_file_exists(outputfilename) == False or kw['overwrite'] == True:
                
                # settings go before the input label/file
                for s in settings:
                    if kw.has_key(s):
                        cmd = cmd + ["-"+s,str(kw[s])]
        
                cmd.append(labelstr_get(lbl))  
                
                # image operators come afterwards
                for im in image_operator:
                    if kw.has_key(im):
                        cmd = cmd + ["-"+im,str(kw[im])]
                
                cmd.append(outputfilename)
    
                p = process_start(cmd)
                
                status = parse_convert_stdout(p,lbl)
                
                if status[0] == 0:
                    self.log.log(self,3,
                                 "created image="+outputfilename,
                                 "status"," ".join(map(str,status)))
                else:
                    self.log.log(self,3,"failed","status="," ".join(map(str,status)))
                    raise Exception("ImageCreate failure",status)
            else:
                self.log.log(self,3,"reused image="+outputfilename)
                
            self.outputfiles.append(outputfilename)
                
        return(self.outputfiles)
コード例 #9
0
def os_dir_exists(dirpath,dirname=""):
    from os.path import join
    return(os_file_exists(join(dirpath,dirname)))
コード例 #10
0
ファイル: csc2vba_array.py プロジェクト: burtnolej/quadviewer
from misc_utils import os_file_to_list, os_file_exists
import sys

if len(sys.argv) == 1:
    print "usage : xsv2vba_array [filepath]"
    exit()
elif os_file_exists(sys.argv[1]) == False:
    print "file not found", sys.argv[1]
    exit()

vba_array_str = ""
lines = os_file_to_list(sys.argv[1])

for linecount in range(0, len(lines)):

    _line = lines[linecount]
    _line = _line.replace("\n", "")
    _line = _line.replace("\"", "")

    errno, errdescr = tuple(_line.split(","))

    if linecount == 0:
        vba_array_str = "\"" + errno + "\",\"" + errdescr + "\""
    else:
        vba_array_str = vba_array_str + ";" + "\n" + "\"" + errno + "\",\"" + errdescr + "\""

print vba_array_str