@@ -61,35 +61,62 @@ def rollback(filename, mode):
6161 shutil .copyfile (f'{ filename } .lock' , filename )
6262
6363
64+ def backup (filename , mode ):
65+ if mode :
66+ # before change, backup
67+ try :
68+ shutil .copyfile (filename , f'{ filename } .undo.bak' )
69+ except :
70+ pass
71+ else :
72+ # after change, restore
73+ try :
74+ shutil .copyfile (f'{ filename } .undo.bak' , filename )
75+ os .remove (f'{ filename } .undo.bak' )
76+ except :
77+ pass
78+
79+
6480if __name__ == "__main__" :
6581 import argparse
6682 parser = argparse .ArgumentParser ()
6783 parser .add_argument ("--recipe" , type = int , required = True , help = 'recipe value' )
84+ parser .add_argument ('--undo' , action = 'store_true' )
6885 args = parser .parse_args ()
86+ TOBACKUP = not args .undo
6987
7088 if args .recipe == 1 :
7189 # chinese
7290 filename = "sustechthesis-example.tex"
73- change_line (filename ,
74- "documentclass.+{sustechthesis}" ,
75- "documentclass[degree=master,language=chinese,cjk-font=external]{sustechthesis}"
76- )
91+ backup (filename , TOBACKUP )
92+ if not args .undo :
93+ change_line (filename ,
94+ "documentclass.+{sustechthesis}" ,
95+ "documentclass[degree=master,language=chinese,cjk-font=external]{sustechthesis}"
96+ )
7797 elif args .recipe == 2 :
7898 # english
7999 filename = "sustechthesis-example.tex"
80- change_line (filename ,
81- "documentclass.+{sustechthesis}" ,
82- "documentclass[degree=master,language=english,cjk-font=external]{sustechthesis}"
83- )
100+ backup (filename , TOBACKUP )
101+ if not args .undo :
102+ change_line (filename ,
103+ "documentclass.+{sustechthesis}" ,
104+ "documentclass[degree=master,language=english,cjk-font=external]{sustechthesis}"
105+ )
84106 elif args .recipe == 3 :
85107 # biber
86108 filename = "sustechthesis-example.tex"
87- comment_line (filename , "bibliography{ref/refs}" , True )
88- comment_line (filename , "printbibliography" , False )
109+ backup (filename , TOBACKUP )
110+ if not args .undo :
111+ comment_line (filename , "bibliography{ref/refs}" , True )
112+ comment_line (filename , "printbibliography" , False )
113+
89114 filename = "sustech-setup.tex"
90- comment_line (filename , "{gbt7714}" , True )
91- comment_line (filename , "citestyle{super}" , True )
92- comment_line (filename , "citestyle{numbers}" , True )
93- comment_line (filename , "bibliographystyle{sustechthesis-numeric}" , True )
94- comment_line (filename , "{biblatex}" , False )
95- comment_line (filename , "addbibresource{ref/refs.bib}" , False )
115+ backup (filename , TOBACKUP )
116+ if not args .undo :
117+ comment_line (filename , "{gbt7714}" , True )
118+ comment_line (filename , "citestyle{super}" , True )
119+ comment_line (filename , "citestyle{numbers}" , True )
120+ comment_line (filename , "bibliographystyle{sustechthesis-numeric}" , True )
121+ comment_line (filename , "{biblatex}" , False )
122+ comment_line (filename , "addbibresource{ref/refs.bib}" , False )
0 commit comments