@@ -764,6 +764,68 @@ def is_task_world(self, conversation_id):
764
764
765
765
# Manager Lifecycle Functions #
766
766
767
+ def populate_legacy_task_files (self , task_directory_path ):
768
+ # Poplulate files to copy over to the server
769
+ if not self .task_files_to_copy :
770
+ self .task_files_to_copy = []
771
+ if not task_directory_path :
772
+ task_directory_path = os .path .join (
773
+ self .opt ['parlai_home' ],
774
+ 'parlai' ,
775
+ 'mturk' ,
776
+ 'tasks' ,
777
+ self .opt ['task' ]
778
+ )
779
+ self .task_files_to_copy .append (
780
+ os .path .join (task_directory_path , 'html' , 'cover_page.html' ))
781
+ try :
782
+ for file_name in os .listdir (os .path .join (
783
+ task_directory_path , 'html' )):
784
+ self .task_files_to_copy .append (os .path .join (
785
+ task_directory_path , 'html' , file_name
786
+ ))
787
+ except FileNotFoundError : # noqa F821 we don't support python2
788
+ # No html dir exists
789
+ pass
790
+ for mturk_agent_id in self .mturk_agent_ids + ['onboarding' ]:
791
+ self .task_files_to_copy .append (os .path .join (
792
+ task_directory_path ,
793
+ 'html' ,
794
+ '{}_index.html' .format (mturk_agent_id )
795
+ ))
796
+
797
+ def populate_task_files (self , task_directory_path ):
798
+ # Poplulate files to copy over to the server
799
+ if not self .task_files_to_copy :
800
+ self .task_files_to_copy = {
801
+ 'static' : [],
802
+ 'components' : [],
803
+ 'css' : [],
804
+ }
805
+ if not task_directory_path :
806
+ task_directory_path = os .path .join (
807
+ self .opt ['parlai_home' ],
808
+ 'parlai' ,
809
+ 'mturk' ,
810
+ 'tasks' ,
811
+ self .opt ['task' ]
812
+ )
813
+ self .task_files_to_copy ['static' ].append (os .path .join (
814
+ task_directory_path , 'frontend' , 'static' , 'cover_page.html' ))
815
+ try :
816
+ frontend_contents = os .listdir (
817
+ os .path .join (task_directory_path , 'frontend' ))
818
+ for dir in frontend_contents :
819
+ if dir in self .task_files_to_copy :
820
+ for file_name in os .listdir (os .path .join (
821
+ task_directory_path , 'frontend' , dir )):
822
+ self .task_files_to_copy [dir ].append (os .path .join (
823
+ task_directory_path , 'frontend' , dir , file_name
824
+ ))
825
+ except FileNotFoundError : # noqa F821 we don't support python2
826
+ # No frontend dir exists
827
+ pass
828
+
767
829
def setup_server (self , task_directory_path = None ):
768
830
"""Prepare the MTurk server for the new HIT we would like to submit"""
769
831
assert self .task_state >= self .STATE_CREATED
@@ -884,34 +946,6 @@ def setup_server(self, task_directory_path=None):
884
946
unique_worker = self .is_unique ,
885
947
is_sandbox = self .opt ['is_sandbox' ]
886
948
)
887
- # Poplulate files to copy over to the server
888
- if not self .task_files_to_copy :
889
- self .task_files_to_copy = []
890
- if not task_directory_path :
891
- task_directory_path = os .path .join (
892
- self .opt ['parlai_home' ],
893
- 'parlai' ,
894
- 'mturk' ,
895
- 'tasks' ,
896
- self .opt ['task' ]
897
- )
898
- self .task_files_to_copy .append (
899
- os .path .join (task_directory_path , 'html' , 'cover_page.html' ))
900
- try :
901
- for file_name in os .listdir (os .path .join (
902
- task_directory_path , 'html' )):
903
- self .task_files_to_copy .append (os .path .join (
904
- task_directory_path , 'html' , file_name
905
- ))
906
- except FileNotFoundError : # noqa F821 we don't support python2
907
- # No html dir exists
908
- pass
909
- for mturk_agent_id in self .mturk_agent_ids + ['onboarding' ]:
910
- self .task_files_to_copy .append (os .path .join (
911
- task_directory_path ,
912
- 'html' ,
913
- '{}_index.html' .format (mturk_agent_id )
914
- ))
915
949
916
950
# Setup the server with a likely-unique app-name
917
951
task_name = '{}-{}' .format (str (uuid .uuid4 ())[:8 ], self .opt ['task' ])
@@ -921,11 +955,18 @@ def setup_server(self, task_directory_path=None):
921
955
heroku_team = self .opt ['heroku_team' ]
922
956
else :
923
957
heroku_team = None
924
- self .server_url = server_utils .setup_server (self .server_task_name ,
925
- self .task_files_to_copy ,
926
- self .opt ['local' ],
927
- heroku_team ,
928
- self .opt ['hobby' ])
958
+
959
+ if self .opt .get ('frontend_version' , 0 ) < 1 :
960
+ self .populate_legacy_task_files (task_directory_path )
961
+ self .server_url = server_utils .setup_legacy_server (
962
+ self .server_task_name , self .task_files_to_copy ,
963
+ self .opt ['local' ], heroku_team , self .opt ['hobby' ])
964
+ else :
965
+ self .populate_task_files (task_directory_path )
966
+ self .server_url = server_utils .setup_server (
967
+ self .server_task_name , self .task_files_to_copy ,
968
+ self .opt ['local' ], heroku_team , self .opt ['hobby' ])
969
+
929
970
shared_utils .print_and_log (logging .INFO , self .server_url )
930
971
931
972
shared_utils .print_and_log (logging .INFO , "MTurk server setup done.\n " ,
0 commit comments