File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 22
22
################################################################################
23
23
24
24
import os
25
+ from enum import Enum
25
26
26
27
# this is the canonical URL. In contrast to all other
27
28
# URL templates, it always links to the official anthology.
@@ -98,3 +99,8 @@ def get_journal_title(top_level_id, volume_title):
98
99
return "Transactions of the Association for Computational Linguistics"
99
100
else :
100
101
return volume_title
102
+
103
+
104
+ class ResourceType (Enum ):
105
+ PDF = 'pdf'
106
+ ATTACHMENT = 'attachments'
Original file line number Diff line number Diff line change @@ -492,3 +492,48 @@ def compute_hash(value: bytes) -> str:
492
492
def compute_hash_from_file (path : str ) -> str :
493
493
with open (path , "rb" ) as f :
494
494
return compute_hash (f .read ())
495
+
496
+
497
+ # For auto upload files to server
498
+ # The root directory for files
499
+ ANTHOLOGY_FILE_ROOT = "anthology-files"
500
+
501
+ # The ssh shortcut (in ~/.ssh/config) or full hostname
502
+ ANTHOLOGY_HOST = "anth"
503
+
504
+
505
+ def upload_file_to_queue (
506
+ local_path : str ,
507
+ resource_type : data .ResourceType ,
508
+ venue_name : str ,
509
+ filename : str ,
510
+ file_hash : str ,
511
+ commit : bool = False ,
512
+ ):
513
+ actual_hash = compute_hash_from_file (local_path )
514
+ if file_hash != actual_hash :
515
+ raise Exception (
516
+ f"Got unexpected hash, file contains incorrect data. (actual hash: { actual_hash } , expected: { file_hash } )"
517
+ )
518
+
519
+ mdkir_cmd = [
520
+ 'ssh' ,
521
+ ANTHOLOGY_HOST ,
522
+ f'mkdir -p { ANTHOLOGY_FILE_ROOT } /queue/{ resource_type .value } /{ venue_name } ' ,
523
+ ]
524
+ if commit :
525
+ subprocess .check_call (mdkir_cmd )
526
+ else :
527
+ logging .info (f"Would run: { mdkir_cmd } " )
528
+
529
+ upload_cmd = [
530
+ "rsync" ,
531
+ "-lptgoDve" ,
532
+ "ssh" ,
533
+ local_path ,
534
+ f"{ ANTHOLOGY_HOST } :{ ANTHOLOGY_FILE_ROOT } /queue/{ resource_type .value } /{ venue_name } /{ filename } .{ file_hash } " ,
535
+ ]
536
+ if commit :
537
+ subprocess .check_call (upload_cmd )
538
+ else :
539
+ logging .info (f"Would run: { upload_cmd } " )
You can’t perform that action at this time.
0 commit comments