Best Python code snippet using playwright-python
folders.py
Source:folders.py  
...42            line=line.rstrip()43            temp=temp+os.path.getsize(line)44            ahdlogger.warn(f"{line}:{temp}" )45        self.size=temp46    def set_files(self,files):47        fd=self.arguments['--fd']48        dir=self.get_dir().rstrip()49        #shell=shellbool,stdout=subprocess.PIPE is true is needed for windows. But cases issues on Linux50        if sys.platform=="linux":51            shellbool=False52        else:53            shellbool=True54        if self.get_type()=="remux2160":55            temp=subprocess.run([fd,'remux','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',56            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')57        elif self.get_type()=="remux1080":58            temp=subprocess.run([fd,'remux','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',59            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')60        elif self.get_type()=="remux720":61            temp=subprocess.run([fd,'remux','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',62            '--exclude','*2160*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')63        elif self.get_type()=="blu2160":64            temp=subprocess.run([fd,'blu','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',65            '--exclude','*720*','--exclude','*480*','--exclude','*[rR][eE][mM][uU][xX]*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',66        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')67        elif self.get_type()=="blu1080":68            temp=subprocess.run([fd,'blu','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',69            '--exclude','*720*','--exclude','*480*','--exclude','*[rR][eE][mM][uU][xX]*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',70        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')71        elif self.get_type()=="blu720":72            temp=subprocess.run([fd,'blu','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',73            '--exclude','*2160*','--exclude','*480*','--exclude','*[rR][eE][mM][uU][xX]*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',74        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')75        elif self.get_type()=="webr2160":76            temp=subprocess.run([fd,'webr','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',77            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',78        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')+subprocess.run([fd,'web-r','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',79            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',80        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')81        elif self.get_type()=="webr1080":82            temp=subprocess.run([fd,'webr','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',83            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',84        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')+subprocess.run([fd,'.web-r','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',85            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',86        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')87        elif self.get_type()=="webr720":88            temp=subprocess.run([fd,'webr','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',89            '--exclude','*1080*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',90        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')+subprocess.run([fd,'.web-r','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',91            '--exclude','*1080*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',92        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')93        elif self.get_type()=="webr480":94            temp=subprocess.run([fd,'webr','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',95            '--exclude','*1080*','--exclude','*720*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',96        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')+subprocess.run([fd,'web-r','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',97       '--exclude','*1080*','--exclude','*720*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')98        elif self.get_type()=="webdl2160":99            temp=subprocess.run([fd,'webdl','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',100            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',101        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')+ subprocess.run([fd,'web-dl','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',102            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',103        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')104        elif self.get_type()=="webdl1080":105            temp=subprocess.run([fd,'webdl','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',106            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',107        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')+ subprocess.run([fd,'web-dl','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',108            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',109        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')110        elif self.get_type()=="webdl720":111            temp=subprocess.run([fd,'webdl','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',112            '--exclude','*1080*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',113        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')+subprocess.run([fd,'web-dl','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',114            '--exclude','*1080*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',115        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')116        elif self.get_type()=="webdl480":117            temp=subprocess.run([fd,'webdl','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',118            '--exclude','*1080*','--exclude','*720*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',119        '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')+subprocess.run([fd,'web-dl','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',120            '--exclude','*1080*','--exclude','*720*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',121            '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')122        elif self.get_type()=="web2160":123            temp=subprocess.run([fd,'*.[wW][eE][bB].*','.',dir,'-d','1','--glob','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',124            '--exclude','*720*','--exclude','*480*','--exclude','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')125        elif self.get_type()=="web1080":126            temp=subprocess.run([fd,'*.[wW][eE][bB].*','.',dir,'-d','1','--glob','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',127            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')128        elif self.get_type()=="web720":129            temp=subprocess.run([fd,'*.[wW][eE][bB].*','.',dir,'-d','1','--glob','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',130            '--exclude','*1080*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')131        elif self.get_type()=="web480":132            temp=subprocess.run([fd,'*.[wW][eE][bB].*','.',dir,'-d','1','--glob','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',133            '--exclude','*1080*','--exclude','*720*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')134        elif self.get_type()=="tv2160":135            temp=subprocess.run([fd,'hdtv','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',136            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')137        elif self.get_type()=="tv1080":138            temp=subprocess.run([fd,'hdtv','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',139            '--exclude','*720*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')140        elif self.get_type()=="tv720":141            temp=subprocess.run([fd,'hdtv','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',142            '--exclude','*2160*','--exclude','*480*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')143        elif self.get_type()=="tv480":144            temp=subprocess.run([fd,'hdtv','.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',145            '--exclude','*2160*','--exclude','*720*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude','*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')146        elif self.get_type()=="other2160":147            temp=subprocess.run([fd,'.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',148            '--exclude','*720*','--exclude','*480*','--exclude','*[rR][eE][mM][uU][xX]*','--exclude','*.[wW][eE][bB]*','--exclude','*.[bB][lL][uU]*','--exclude','*[tT][vV]*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',149            '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')150        elif self.get_type()=="other1080":151            temp=subprocess.run([fd,'.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*2160*',152            '--exclude','*720*','--exclude','*480*','--exclude','*[rR][eE][mM][uU][xX]*','--exclude','*.[wW][eE][bB]*','--exclude','*.[bB][lL][uU]*','--exclude','*[tT][vV]*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',153            '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')154        elif self.get_type()=="other720":155            temp=subprocess.run([fd,'.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',156            '--exclude','*2160*','--exclude','*480*','--exclude','*[rR][eE][mM][uU][xX]*','--exclude','*.[wW][eE][bB]*','--exclude','*.[bB][lL][uU]*','--exclude','*[tT][vV]*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',157            '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')158        elif self.get_type()=="other480":159            temp=subprocess.run([fd,'.',dir,'-d','1','-e','.mkv','-e','.mp4','-e','.m4v','--exclude','*1080*',160            '--exclude','*2160*','--exclude','*720*','--exclude','480','--exclude','*[rR][eE][mM][uU][xX]*','--exclude','*.[wW][eE][bB]*','--exclude','*.[bB][lL][uU]*','--exclude','*[tT][vV]*','--exclude','*[sS][aA][mM][pP][lL][eE]*','--exclude',161            '*[tT][rR][aA][iL][eE][rR]*'],shell=shellbool,stdout=subprocess.PIPE).stdout.decode('utf-8')162        if len(temp)==0:163            ahdlogger.debug(f"No Matching Files for Search")164        else:165            ahdlogger.debug(f"List of Files in Directory: {temp}")166        files.write(temp)167        self.files=files168    def get_first(self):169        files=self.get_files()170        try:171            files.seek(0, 0)172            first=files.readlines()[0]173            ahdlogger.warn(f"Using for search: {first}")174            return first175        except:176            return "No Files"177    """178    Missing files Functions179    """180def scan_folder(arguments,line,source):181    if source['remux']=='yes':182        files=tempfile.NamedTemporaryFile('w+')183        remux1=Folder(line,"remux1080",arguments)184        remux1.set_files(files)185        remux1.set_size()186        get_missing(arguments,remux1)187        files.close()188        files=tempfile.NamedTemporaryFile('w+')189        remux2=Folder(line,"remux2160",arguments)190        remux2.set_files(files)191        remux2.set_size()192        get_missing(arguments,remux2)193        files.close()194        files=tempfile.NamedTemporaryFile('w+')195        remux3=Folder(line,"remux720",arguments)196        remux3.set_files(files)197        remux3.set_size()198        get_missing(arguments,remux3)199        files.close()200    if source['blu']=='yes':201        files=tempfile.NamedTemporaryFile('w+')202        blu1=Folder(line,"blu1080",arguments)203        blu1.set_files(files)204        blu1.set_size()205        get_missing(arguments,blu1)206        files.close()207        files=tempfile.NamedTemporaryFile('w+')208        blu2=Folder(line,"blu2160",arguments)209        blu2.set_files(files)210        blu2.set_size()211        get_missing(arguments,blu2)212        files.close()213        files=tempfile.NamedTemporaryFile('w+')214        blu3=Folder(line,"blu720",arguments)215        blu3.set_files(files)216        blu3.set_size()217        get_missing(arguments,blu3)218        files.close()219    if source['tv']=='yes':220        files=tempfile.NamedTemporaryFile('w+')221        tv1=Folder(line,"tv1080",arguments)222        tv1.set_files(files)223        tv1.set_size()224        get_missing(arguments,tv1,True)225        files.close()226        files=tempfile.NamedTemporaryFile('w+')227        tv2=Folder(line,"tv2160",arguments)228        tv2.set_files(files)229        tv2.set_size()230        get_missing(arguments,tv2,True)231        files.close()232        files=tempfile.NamedTemporaryFile('w+')233        tv3=Folder(line,"tv720",arguments)234        tv3.set_files(files)235        tv3.set_size()236        get_missing(arguments,tv3,True)237        files.close()238        files=tempfile.NamedTemporaryFile('w+')239        tv4=Folder(line,"tv480",arguments)240        tv4.set_files(files)241        tv4.set_size()242        get_missing(arguments,tv4,True)243        files.close()244    if source['other']=='yes':245        files=tempfile.NamedTemporaryFile('w+')246        other1=Folder(line,"other1080",arguments)247        other1.set_files(files)248        other1.set_size()249        get_missing(arguments,other1,True)250        files.close()251        files=tempfile.NamedTemporaryFile('w+')252        other2=Folder(line,"other2160",arguments)253        other2.set_files(files)254        other2.set_size()255        get_missing(arguments,other2,True)256        files.close()257        files=tempfile.NamedTemporaryFile('w+')258        other3=Folder(line,"other720",arguments)259        other3.set_files(files)260        other3.set_size()261        get_missing(arguments,other3,True)262        files.close()263        files=tempfile.NamedTemporaryFile('w+')264        other4=Folder(line,"other480",arguments)265        other4.set_files(files)266        other4.set_size()267        get_missing(arguments,other4,True)268        files.close()269    if source['web']=='yes':270        files=tempfile.NamedTemporaryFile('w+')271        web1=Folder(line,"web1080",arguments)272        web1.set_files(files)273        web1.set_size()274        get_missing(arguments,web1,True)275        files.close()276        files=tempfile.NamedTemporaryFile('w+')277        web2=Folder(line,"web2160",arguments)278        web2.set_files(files)279        web2.set_size()280        get_missing(arguments,web2,True)281        files.close()282        files=tempfile.NamedTemporaryFile('w+')283        web3=Folder(line,"web720",arguments)284        web3.set_files(files)285        web3.set_size()286        get_missing(arguments,web3,True)287        files.close()288        files=tempfile.NamedTemporaryFile('w+')289        web4=Folder(line,"web480",arguments)290        web4.set_files(files)291        web4.set_size()292        get_missing(arguments,web4,True)293        files.close()294        files=tempfile.NamedTemporaryFile('w+')295        webr1=Folder(line,"webr1080",arguments)296        webr1.set_files(files)297        webr1.set_size()298        get_missing(arguments,webr1,True)299        files.close()300        files=tempfile.NamedTemporaryFile('w+')301        webr2=Folder(line,"webr2160",arguments)302        webr2.set_files(files)303        webr2.set_size()304        get_missing(arguments,webr2,True)305        files.close()306        files=tempfile.NamedTemporaryFile('w+')307        webr3=Folder(line,"webr720",arguments)308        webr3.set_files(files)309        webr3.set_size()310        get_missing(arguments,webr3,True)311        files.close()312        files=tempfile.NamedTemporaryFile('w+')313        webr4=Folder(line,"webr480",arguments)314        webr4.set_files(files)315        webr4.set_size()316        get_missing(arguments,webr4,True)317        files.close()318        files=tempfile.NamedTemporaryFile('w+')319        webdl1=Folder(line,"webdl1080",arguments)320        webdl1.set_files(files)321        webdl1.set_size()322        get_missing(arguments,webdl1)323        files.close()324        files=tempfile.NamedTemporaryFile('w+')325        webdl2=Folder(line,"webdl2160",arguments)326        webdl2.set_files(files)327        webdl2.set_size()328        get_missing(arguments,webdl2)329        files.close()330        files=tempfile.NamedTemporaryFile('w+')331        webdl3=Folder(line,"webdl720",arguments)332        webdl3.set_files(files)333        webdl3.set_size()334        get_missing(arguments,webdl3)335        files.close()336        files=tempfile.NamedTemporaryFile('w+')337        webdl4=Folder(line,"webdl480",arguments)338        webdl4.set_files(files)339        webdl4.set_size()340        get_missing(arguments,webdl4)341        files.close()342    """343Cross Seed Torrent or Output Functions344"""345def download_folder(arguments,line,source):346    if source['remux']=='yes':347        files=tempfile.NamedTemporaryFile('w+')348        remux1=Folder(line,"remux1080",arguments)349        remux1.set_files(files)350        remux1.set_size()351        get_matches(arguments,remux1)352        files.close()353        files=tempfile.NamedTemporaryFile('w+')354        remux2=Folder(line,"remux2160",arguments)355        remux2.set_files(files)356        remux2.set_size()357        get_matches(arguments,remux2)358        files.close()359        files=tempfile.NamedTemporaryFile('w+')360        remux3=Folder(line,"remux720",arguments)361        remux3.set_files(files)362        remux3.set_size()363        get_matches(arguments,remux3)364        files.close()365    if source['blu']=='yes':366        files=tempfile.NamedTemporaryFile('w+')367        blu1=Folder(line,"blu1080",arguments)368        blu1.set_files(files)369        blu1.set_size()370        get_matches(arguments,blu1)371        files.close()372        files=tempfile.NamedTemporaryFile('w+')373        blu2=Folder(line,"blu2160",arguments)374        blu2.set_files(files)375        blu2.set_size()376        get_matches(arguments,blu2)377        files.close()378        files=tempfile.NamedTemporaryFile('w+')379        blu3=Folder(line,"blu720",arguments)380        blu3.set_files(files)381        blu3.set_size()382        get_matches(arguments,blu3)383        files.close()384    if source['tv']=='yes':385        files=tempfile.NamedTemporaryFile('w+')386        tv1=Folder(line,"tv1080",arguments)387        tv1.set_files(files)388        tv1.set_size()389        get_matches(arguments,tv1)390        files.close()391        files=tempfile.NamedTemporaryFile('w+')392        tv2=Folder(line,"tv2160",arguments)393        tv2.set_files(files)394        tv2.set_size()395        get_matches(arguments,tv2)396        files.close()397        files=tempfile.NamedTemporaryFile('w+')398        tv3=Folder(line,"tv720",arguments)399        tv3.set_files(files)400        tv3.set_size()401        get_matches(arguments,tv3)402        files.close()403        files=tempfile.NamedTemporaryFile('w+')404        tv4=Folder(line,"tv480",arguments)405        tv4.set_files(files)406        tv4.set_size()407        get_matches(arguments,tv4)408        files.close()409    if source['other']=='yes':410        files=tempfile.NamedTemporaryFile('w+')411        other1=Folder(line,"other1080",arguments)412        other1.set_files(files)413        other1.set_size()414        get_matches(arguments,other1)415        files.close()416        files=tempfile.NamedTemporaryFile('w+')417        other2=Folder(line,"other2160",arguments)418        other2.set_files(files)419        other2.set_size()420        get_matches(arguments,other2)421        files.close()422        files=tempfile.NamedTemporaryFile('w+')423        other3=Folder(line,"other720",arguments)424        other3.set_files(files)425        other3.set_size()426        get_matches(arguments,other3)427        files.close()428        files=tempfile.NamedTemporaryFile('w+')429        other4=Folder(line,"other480",arguments)430        other4.set_files(files)431        other4.set_size()432        get_matches(arguments,other4)433        files.close()434    if source['web']=='yes':435        files=tempfile.NamedTemporaryFile('w+')436        web1=Folder(line,"web1080",arguments)437        web1.set_files(files)438        web1.set_size()439        get_matches(arguments,web1)440        files.close()441        files=tempfile.NamedTemporaryFile('w+')442        web2=Folder(line,"web2160",arguments)443        web2.set_files(files)444        web2.set_size()445        get_matches(arguments,web2)446        files.close()447        files=tempfile.NamedTemporaryFile('w+')448        web3=Folder(line,"web720",arguments)449        web3.set_files(files)450        web3.set_size()451        get_matches(arguments,web3)452        files.close()453        files=tempfile.NamedTemporaryFile('w+')454        web4=Folder(line,"web480",arguments)455        web4.set_files(files)456        web4.set_size()457        get_matches(arguments,web4)458        files.close()459        files=tempfile.NamedTemporaryFile('w+')460        webr1=Folder(line,"webr1080",arguments)461        webr1.set_files(files)462        webr1.set_size()463        get_matches(arguments,webr1)464        files.close()465        files=tempfile.NamedTemporaryFile('w+')466        webr2=Folder(line,"webr2160",arguments)467        webr2.set_files(files)468        webr2.set_size()469        get_matches(arguments,webr2)470        files.close()471        files=tempfile.NamedTemporaryFile('w+')472        webr3=Folder(line,"webr720",arguments)473        webr3.set_files(files)474        webr3.set_size()475        get_matches(arguments,webr3)476        files.close()477        files=tempfile.NamedTemporaryFile('w+')478        webr4=Folder(line,"webr480",arguments)479        webr4.set_files(files)480        webr4.set_size()481        get_matches(arguments,webr4)482        files.close()483        files=tempfile.NamedTemporaryFile('w+')484        webdl1=Folder(line,"webdl1080",arguments)485        webdl1.set_files(files)486        webdl1.set_size()487        get_matches(arguments,webdl1)488        files.close()489        files=tempfile.NamedTemporaryFile('w+')490        webdl2=Folder(line,"webdl2160",arguments)491        webdl2.set_files(files)492        webdl2.set_size()493        get_matches(arguments,webdl2)494        files.close()495        files=tempfile.NamedTemporaryFile('w+')496        webdl3=Folder(line,"webdl720",arguments)497        webdl3.set_files(files)498        webdl3.set_size()499        get_matches(arguments,webdl3)500        files.close()501        files=tempfile.NamedTemporaryFile('w+')502        webdl4=Folder(line,"webdl480",arguments)503        webdl4.set_files(files)504        webdl4.set_size()505        get_matches(arguments,webdl4)...assemble_augment_test.py
Source:assemble_augment_test.py  
...62            os.remove(data_file)63    # Do an event with model.conf (not model_select.conf) and no zoneinfo64    # (should succeed)65    event_path = os.path.join(datapath, "nc72282711", "current")66    set_files(67        event_path,68        {69            "event.xml": "event.xml",70            "stationlist.xml": "stationlist.xml",71            "boat_fault.txt": "boat_fault.txt",72            "model.conf": "model.conf",73        },74    )75    data_file = os.path.join(datapath, "nc72282711", "current", "shake_data.hdf")76    if os.path.isfile(data_file):77        os.remove(data_file)78    try:79        assemble = AssembleModule("nc72282711", comment="Test comment.")80        assemble.execute()81        augment = AugmentModule("nc72282711", comment="Test comment.")82        augment.execute()83    finally:84        if os.path.isfile(data_file):85            os.remove(data_file)86        clear_files(event_path)87    # Try not having an event-specific config (should succeed)88    set_files(89        event_path,90        {91            "event.xml": "event.xml",92            "stationlist.xml": "stationlist.xml",93            "boat_fault.txt": "boat_fault.txt",94        },95    )96    try:97        amod = AssembleModule("nc72282711", comment="Test comment.")98        amod.execute()99        augment = AugmentModule("nc72282711", comment="Test comment.")100        augment.execute()101    finally:102        if os.path.isfile(data_file):103            os.remove(data_file)104        clear_files(event_path)105    # Do an event with DYFI data (should succeed)106    set_files(107        event_path,108        {109            "event.xml": "event.xml",110            "stationlist.xml": "stationlist.xml",111            "boat_fault.txt": "boat_fault.txt",112            "dyfi_dat.xml": "dyfi_dat.xml",113        },114    )115    try:116        amod = AssembleModule("nc72282711", comment="Test comment.")117        amod.execute()118        augment = AugmentModule("nc72282711", comment="Test comment.")119        augment.execute()120    finally:121        if os.path.isfile(data_file):122            os.remove(data_file)123        clear_files(event_path)124    #125    # Try some bad config files126    #127    # Should fail validation128    set_files(129        event_path,130        {"event.xml": "event.xml", "model_select.conf.bad0": "model_select.conf"},131    )132    try:133        amod = AssembleModule("nc72282711", comment="Test comment.")134        with pytest.raises(RuntimeError):135            amod.execute()136    finally:137        clear_files(event_path)138    # Should fail vs30 filename check139    set_files(140        event_path,141        {"event.xml": "event.xml", "model_select.conf.bad1": "model_select.conf"},142    )143    try:144        amod = AssembleModule("nc72282711", comment="Test comment.")145        with pytest.raises(RuntimeError):146            amod.execute()147    finally:148        clear_files(event_path)149    # Should fail prediction locations filename check150    set_files(151        event_path,152        {"event.xml": "event.xml", "model_select.conf.bad2": "model_select.conf"},153    )154    try:155        amod = AssembleModule("nc72282711", comment="Test comment.")156        with pytest.raises(FileNotFoundError):157            amod.execute()158    finally:159        clear_files(event_path)160    #161    # Make sure the location file substitutions work (should succeed)162    #163    data_file = os.path.join(datapath, "northridge_points", "current", "shake_data.hdf")164    if os.path.isfile(data_file):165        os.remove(data_file)166    try:167        assemble = AssembleModule("northridge_points", comment="Test comment.")168        assemble.execute()169        augment = AugmentModule("northridge_points", comment="Test comment.")170        augment.execute()171    finally:172        if os.path.isfile(data_file):173            os.remove(data_file)174    #175    # Try some bad config files176    #177    try:178        set_files(event_path, {"event.xml": "event.xml"})179        assemble = AssembleModule("nc72282711", comment="Test comment.")180        assemble.execute()181        # Should fail validation182        set_files(event_path, {"model_select.conf.bad0": "model_select.conf"})183        augment = AugmentModule("nc72282711", comment="Test comment.")184        with pytest.raises(RuntimeError):185            augment.execute()186        clear_files(event_path)187        # Should fail vs30 filename check188        set_files(event_path, {"event.xml": "event.xml"})189        assemble = AssembleModule("nc72282711", comment="Test comment.")190        assemble.execute()191        set_files(192            event_path,193            {"event.xml": "event.xml", "model_select.conf.bad1": "model_select.conf"},194        )195        augment = AugmentModule("nc72282711", comment="Test comment.")196        with pytest.raises(RuntimeError):197            augment.execute()198        clear_files(event_path)199        # Should fail prediction locations filename check200        set_files(event_path, {"event.xml": "event.xml"})201        assemble = AssembleModule("nc72282711", comment="Test comment.")202        assemble.execute()203        set_files(204            event_path,205            {"event.xml": "event.xml", "model_select.conf.bad2": "model_select.conf"},206        )207        augment = AugmentModule("nc72282711", comment="Test comment.")208        with pytest.raises(FileNotFoundError):209            augment.execute()210    finally:211        clear_files(event_path)212    #213    # Switch originators (should succeed)214    #215    set_files(event_path, {"event.xml": "event.xml", "model.conf.cz": "model.conf"})216    try:217        assemble = AssembleModule("nc72282711", comment="Test comment.")218        assemble.execute()219        augment = AugmentModule("nc72282711", comment="Test comment.")220        augment.execute()221    finally:222        if os.path.isfile(data_file):223            os.remove(data_file)224        clear_files(event_path)225def test_assemble_augment_command_line():226    installpath, datapath = get_config_paths()227    cp = subprocess.run(228        [229            "shake",...pth.py
Source:pth.py  
1import os2import os.path as op3import re4from pathlib import Path5import numpy as np6from borsar.project import Paths, get_valid_path7from sarna.proj import find_dropbox8global paths9global files10global files_id_mode11files = dict()12paths = Paths()13# study C14# -------15def set_paths(base_dir=None):16    '''Setup study paths. Creates a borsar Paths object that allows other17    functions to work for all registered studies.18    Parameters19    ----------20    base_dir : str21        Base directory - that is a directory on your computer that contains22        all study subfolders. See the github documentation to see what files23        are necessary for studies to be included in specific analyses or how24        to add additional studies.25    Returns26    -------27    paths : borsar.project.Paths28        Paths object containing information on folders and data-reading29        functions. Allows to get paths for specific study folders (for30        example ``paths.get_path('eeg', study='C', task='rest')``) or31        to read files like behavioral data32        (``paths.get_data('bdi', study='C')``) or precomputed spectra33        (``paths.get_data('psd', study='B')``).34    '''35    global paths36    global files37    global files_id_mode38    paths = Paths()39    paths.register_study('C', tasks=['rest', 'sternberg', 'linord'])40    if base_dir is not None:41        paths.add_path('base', base_dir, relative_to=False)42    else:43        raise ValueError('You have to specify base directory')44    # study C45    # -------46    has_study = dict()47    has_study['C'] = (paths.get_path('base', as_str=False)48                      / 'DiamSar').exists()49    if has_study['C']:50        paths.add_path('main', 'DiamSar', relative_to='base')51        paths.add_path('fig', 'fig', validate=False)52        paths.add_path('eeg', 'eeg')53        paths.add_path('subjects_dir', 'src', relative_to='eeg')54        paths.add_path('src', 'src', relative_to='eeg')55        paths.add_path('beh_base', 'beh', relative_to='main')56        paths.add_path('beh', 'stern', task='sternberg',57                       relative_to='beh_base', validate=False)58        # task-specific data59        translate = dict(rest='baseline', linord='linord',60                         sternberg='sternberg')61        for task in ['rest', 'sternberg']:62            task_eeg_dir = op.join('resampled set', translate[task]63                                   + '_clean_exported')64            paths.add_path('eeg', task_eeg_dir, study='C', task=task,65                           relative_to='eeg', validate=False)66    # study A, B, D & E67    # -----------------68    base_dir = paths.get_path('base')69    study_dirs = ['Nowowiejska', 'Wronski', 'PREDiCT', 'MODMA']70    prefixes = ['baseline', 'baseline', 'rest', 'baseline']71    for study, study_dir, prefix in zip(list('ABDE'), study_dirs, prefixes):72        paths.register_study(study, tasks=['rest'])73        this_study_path = Path(base_dir, study_dir)74        has_study[study] = this_study_path.exists()75        if has_study[study]:76            paths.add_path('main', this_study_path, study=study)77            paths.add_path('eeg', 'eeg', study=study)78            paths.add_path('src', 'src', study=study, relative_to='eeg')79            # task-specific80            paths.add_path('eeg', prefix + '_clean_exported', study=study,81                           task='rest', relative_to='eeg', validate=False)82    # channel position for all studies83    for study in paths.studies:84        if has_study[study]:85            paths.add_path('chanpos', 'chanpos', study=study,86                           relative_to='eeg', validate=False)87    # getting files88    # -------------89    # getting files is not yet supported in borsar.Paths so we write a few90    # functions for that91    files_id_mode = dict(A='anon', B='num', C='num', D='num', E='num')92    for study in paths.studies:93        files[study] = dict()94        for task in paths.tasks[study]:95            files[study][task] = list()96        # scan data files if study is present97        if has_study[study]:98            scan_files(study=study)99    # register data100    # -------------101    from .io import (load_GH, load_chanord, load_neighbours, load_info,102                     load_forward, load_src_sym, read_bdi, load_psd)103    for study in paths.studies:104        if has_study[study]:105            paths.register_data('GH', load_GH, study=study, cache=True)106            paths.register_data('chanord', load_chanord, study=study,107                                cache=True)108            paths.register_data('neighbours', load_neighbours, study=study)109            paths.register_data('info', load_info, study=study, cache=True)110            paths.register_data('bdi', read_bdi, study=study, cache=False)111            paths.register_data('psd', load_psd, study=study, cache=False)112            paths.register_data('fwd', load_forward, study=study)113    paths.register_data('src_sym', load_src_sym, study='C')114    return paths115def scan_files(study='C', task='rest'):116    '''Refresh the list of files for given study / task eeg directory.'''117    global files118    task_dir = paths.get_path('eeg', study=study, task=task)119    if op.isdir(task_dir):120        set_files = [f for f in os.listdir(task_dir) if f.endswith('.set')]121        rej_files = [f for f in os.listdir(task_dir) if f.endswith('.rej')]122        subj_id = [int(re.findall('[0-9]+', f)[0]) for f in set_files]123        files[study][task] = set_files, rej_files, subj_id124    else:125        files[study][task] = None, None, None126def get_file(file, study='C', task='rest'):127    '''128    Get `.set` and `.rej` filenames for given subject ID from specific129    study and task.130    '''131    global files132    global files_id_mode133    scan_files(study=study, task=task)134    set_files, rej_files, subj_id = files[study][task]135    # deal with subject identifiers, first in str format136    # (for example '2', '01', '042' or '003')137    if isinstance(file, str) and len(file) < 4:138        if file.isdigit():139            file = int(file)140    # deal with integers - subject identifiers141    if isinstance(file, int):142        if files_id_mode[study] == 'num':143            if file not in subj_id:144                msg = 'Given id ({}) was not found for study {}, task {}.'145                raise FileNotFoundError(msg.format(file, study, task))146            else:147                idx = subj_id.index(file)148                set_file = set_files[idx]149        elif files_id_mode[study] == 'anon':150            if file > len(set_files):151                msg = ('Requested file number {} while there are only '152                       '{} files for study {}, task {}.')153                raise FileNotFoundError(msg.format(file, len(set_files),154                                                   study, task))155            set_file = set_files[file - 1]156    else:157        set_file = file158        if set_file in set_files:159            msg = 'Given files ({}) was not found for study {}, task {}.'160            raise FileNotFoundError(msg.format(set_file, study, task))161    rej_file = set_file.replace('.set', '.rej')162    if rej_file not in rej_files:163        rej_file = None164    return set_file, rej_file165def get_subject_ids(study='C', task='rest', full_names=False):166    '''167    Get subject id's for specific study and task.168    '''169    global files170    global files_id_mode171    if files_id_mode[study] == 'num':172        set_files, _, subj_ids = files[study][task]173    elif files_id_mode[study] == 'anon':174        set_files, _, _ = files[study][task]175        subj_ids = list(range(1, len(set_files) + 1))176    if full_names:177        names = np.array([f.replace('.set', '') for f in set_files])178        return subj_ids, names179    else:180        return subj_ids181try:182    # automatic path setup for computers we frequently used183    dropbox_dir = find_dropbox()184    if len(dropbox_dir) > 0:185        candidate_paths = [op.join(dropbox_dir, p)186                           for p in ['DANE/SarenkaData', 'DATA']]187        full_path = get_valid_path(candidate_paths)188        paths = set_paths(base_dir=full_path)189except:...model_test.py
Source:model_test.py  
...16    # This is a small grid with station data and dyfi data (should succeed)17    #18    install_path, data_path = get_config_paths()19    event_path = os.path.join(data_path, "nc72282711", "current")20    set_files(21        event_path,22        {23            "event.xml": "event.xml",24            "stationlist.xml.small": "stationlist.xml",25            "dyfi_dat.xml.small": "dyfi_dat.xml",26            "model.conf": "model.conf",27            "boat_fault.txt": "boat_fault.txt",28        },29    )30    assemble = AssembleModule("nc72282711", comment="Test comment.")31    assemble.execute()32    del assemble33    model = ModelModule("nc72282711")34    model.execute()35    del model36    #37    # Since we've done this, we might as well run plotregr, too38    #39    plotregr = PlotRegr("nc72282711")40    plotregr.execute()41    plotregr.writeContents()42    del plotregr43    clear_files(event_path)44def test_model_3():45    #46    # This is a small grid with DYFI data only (should succeed)47    #48    install_path, data_path = get_config_paths()49    event_path = os.path.join(data_path, "nc72282711", "current")50    set_files(51        event_path,52        {53            "event.xml": "event.xml",54            "dyfi_dat.xml.small": "dyfi_dat.xml",55            "model.conf": "model.conf",56            "boat_fault.txt": "boat_fault.txt",57        },58    )59    assemble = AssembleModule("nc72282711", comment="Test comment.")60    assemble.execute()61    model = ModelModule("nc72282711")62    model.execute()63    clear_files(event_path)64def test_model_4():65    #66    # Run with no data and no fault, and use the default extent.67    #68    install_path, data_path = get_config_paths()69    event_path = os.path.join(data_path, "nc72282711", "current")70    set_files(event_path, {"event.xml": "event.xml", "model.conf": "model.conf"})71    assemble = AssembleModule("nc72282711", comment="Test comment.")72    assemble.execute()73    model = ModelModule("nc72282711")74    model.execute()75    clear_files(event_path)76def test_model_sim():77    #78    # Run with no data and no fault, and use the default extent.79    #80    install_path, data_path = get_config_paths()81    # event_path = os.path.join(data_path, 'planet9', 'current')82    assemble = AssembleModule("planet9", comment="Test comment.")83    assemble.execute()84    model = ModelModule("planet9")85    model.execute()86def test_directivity():87    #88    # Turned on directivity in model.conf89    #90    install_path, data_path = get_config_paths()91    event_path = os.path.join(data_path, "directivity_test", "current")92    set_files(93        event_path,94        {95            "event.xml": "event.xml",96            "model.conf": "model.conf",97            "dir_fault.txt": "dir_fault.txt",98        },99    )100    assemble = AssembleModule("directivity_test", comment="Test comment.")101    assemble.execute()102    model = ModelModule("directivity_test")103    model.execute()104    clear_files(event_path)105    hdf_file = os.path.join(event_path, "products", "shake_result.hdf")106    oc = ShakeMapOutputContainer.load(hdf_file)107    sa3 = np.exp(oc.getIMTGrids("SA(3.0)", "GREATER_OF_TWO_HORIZONTAL")["mean"])108    # np.testing.assert_allclose(np.max(sa3), 1.15864273)109    np.testing.assert_allclose(np.max(sa3), 1.1567265149442174)110    # np.testing.assert_allclose(np.min(sa3), 0.9278920)111    np.testing.assert_allclose(np.min(sa3), 0.88508818541678)112    oc.close()113def test_masking():114    install_path, data_path = get_config_paths()115    event_path = os.path.join(data_path, "masking_test", "current")116    set_files(117        event_path,118        {119            "event.xml": "event.xml",120            "model.conf": "model.conf",121            "au_continental_shelf.geojson": "au_continental_shelf.geojson",122        },123    )124    assemble = AssembleModule("masking_test", comment="Test comment.")125    assemble.execute()126    model = ModelModule("masking_test")127    model.execute()128    clear_files(event_path)129    hdf_file = os.path.join(event_path, "products", "shake_result.hdf")130    oc = ShakeMapOutputContainer.load(hdf_file)...LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!
