@@ -377,7 +377,7 @@ def progress_helper():
377
377
progress .progressing = False
378
378
379
379
380
- def submit (org , problem ):
380
+ def submit (org , branch ):
381
381
"""Submit problem."""
382
382
383
383
# check announcements
@@ -388,11 +388,11 @@ def submit(org, problem):
388
388
# require git 2.7+, so that credential-cache--daemon ignores SIGHUP
389
389
# https://github.com/git/git/blob/v2.7.0/credential-cache--daemon.c
390
390
if not which ("git" ):
391
- raise Error (_ ("You don't have git. Install git, then re-run submit50!" ))
391
+ raise Error (_ ("You don't have git. Install git, then re-run {}!" . format ( org ) ))
392
392
version = subprocess .check_output (["git" , "--version" ]).decode ("utf-8" )
393
393
matches = re .search (r"^git version (\d+\.\d+\.\d+).*$" , version )
394
394
if not matches or StrictVersion (matches .group (1 )) < StrictVersion ("2.7.0" ):
395
- raise Error (_ ("You have an old version of git. Install version 2.7 or later, then re-run submit50!" ))
395
+ raise Error (_ ("You have an old version of git. Install version 2.7 or later, then re-run {}!" . format ( org ) ))
396
396
397
397
# update progress
398
398
progress ("Connecting" )
@@ -411,16 +411,20 @@ def submit(org, problem):
411
411
version_required = res .text .strip ()
412
412
if parse_version (version_required ) > parse_version (get_distribution ("submit50" ).version ):
413
413
raise Error (_ ("You have an old version of submit50. "
414
- "Run update50, then re-run submit50!" ))
414
+ "Run update50, then re-run {}!" . format ( org ) ))
415
415
416
- # assume cs50/ problem if problem name begins with a year
417
- branch = problem
418
- if problem .split ("/" )[0 ].isdigit ():
419
- branch = os .path .join ("cs50" , problem )
416
+ file , submit .EXCLUDE = tempfile .mkstemp ()
417
+
418
+ # separate branch into problem slug and source repo
419
+ check_repo = "@cs50/checks"
420
+ branch = branch if not branch .endswith (check_repo ) else branch [:- len (check_repo )]
421
+ try :
422
+ slug , src = branch .split ("@" )
423
+ except ValueError :
424
+ slug , src = branch , "cs50/checks"
420
425
421
426
# ensure problem exists
422
- file , submit .EXCLUDE = tempfile .mkstemp ()
423
- url = "https://cs50.me/excludes/{}/" .format (branch )
427
+ url = "https://raw.githubusercontent.com/{}/master/{}/submit50/exclude" .format (src , slug )
424
428
try :
425
429
urllib .request .urlretrieve (url , filename = submit .EXCLUDE )
426
430
lines = open (submit .EXCLUDE )
@@ -474,12 +478,12 @@ def submit(org, problem):
474
478
run ("git clone --bare {} {}" .format (shlex .quote (repo ), shlex .quote (run .GIT_DIR )), password = password )
475
479
except :
476
480
if password :
477
- e = Error (_ ("Looks like submit50 isn't enabled for your account yet. "
478
- "Log into https://cs50.me/ in a browser, click \" Authorize application\" , and re-run submit50 here!" ))
481
+ e = Error (_ ("Looks like {} isn't enabled for your account yet. "
482
+ "Log into https://cs50.me/ in a browser, click \" Authorize application\" , and re-run {} here!" . format ( org , org ) ))
479
483
else :
480
- e = Error (_ ("Looks like you have the wrong username in ~/.gitconfig or submit50 isn't yet enabled for your account. "
484
+ e = Error (_ ("Looks like you have the wrong username in ~/.gitconfig or {} isn't yet enabled for your account. "
481
485
"Double-check ~/.gitconfig and then log into https://cs50.me/ in a browser, "
482
- "click \" Authorize application\" if prompted, and re-run submit50 here." ))
486
+ "click \" Authorize application\" if prompted, and re-run {} here." . format ( org , org ) ))
483
487
e .__cause__ = None
484
488
raise e
485
489
@@ -525,14 +529,14 @@ def submit(org, problem):
525
529
elif size > (2 * 1024 * 1024 * 1024 ):
526
530
huge .append (file )
527
531
if len (huge ) > 0 :
528
- raise Error ("These files are too large to be submitted:\n {}\n "
529
- "Remove these files from your directory "
530
- "and then re-run submit50!" .format ("\n " .join (huge )))
532
+ raise Error (_ ( "These files are too large to be submitted:\n {}\n "
533
+ "Remove these files from your directory "
534
+ "and then re-run {}!" ) .format ("\n " .join (huge ), org ))
531
535
elif len (large ) > 0 :
532
536
if not which ("git-lfs" ):
533
- raise Error ("These files are too large to be submitted:\n {}\n "
534
- "Install git-lfs (or remove these files from your directory) "
535
- "and then re-run submit50!" .format ("\n " .join (large )))
537
+ raise Error (_ ( "These files are too large to be submitted:\n {}\n "
538
+ "Install git-lfs (or remove these files from your directory) "
539
+ "and then re-run {}!" ) .format ("\n " .join (large ), org ))
536
540
run ("git lfs install --local" )
537
541
run ("git config credential.helper cache" ) # for pre-push hook
538
542
for file in large :
@@ -542,33 +546,38 @@ def submit(org, problem):
542
546
# files that will be submitted
543
547
if len (files ) == 0 :
544
548
raise Error (_ ("No files in this directory are expected for submission." ))
545
- cprint (_ ("Files that will be submitted:" ), "green" )
546
- for f in files :
547
- cprint ("./{}" .format (f ), "green" )
548
-
549
- # files that won't be submitted
550
- if len (other ) != 0 :
551
- cprint (_ ("Files that won't be submitted:" ), "yellow" )
552
- for f in other :
553
- cprint ("./{}" .format (f ), "yellow" )
554
-
555
- # prompt for academic honesty
556
- answer = input (_ ("Keeping in mind the course's policy on academic honesty, "
557
- "are you sure you want to submit these files? " ))
558
- if not re .match ("^\s*(?:y|yes)\s*$" , answer , re .I ):
559
- raise Error (_ ("No files were submitted." ))
549
+
550
+ if org == "submit50" :
551
+ cprint (_ ("Files that will be submitted:" ), "green" )
552
+ for f in files :
553
+ cprint ("./{}" .format (f ), "green" )
554
+
555
+ # files that won't be submitted
556
+ if len (other ) != 0 :
557
+ cprint (_ ("Files that won't be submitted:" ), "yellow" )
558
+ for f in other :
559
+ cprint ("./{}" .format (f ), "yellow" )
560
+
561
+ answer = input (_ ("Keeping in mind the course's policy on academic honesty, "
562
+ "are you sure you want to submit these files? " ))
563
+ if not re .match ("^\s*(?:y|yes)\s*$" , answer , re .I ):
564
+ raise Error (_ ("No files were submitted." ))
560
565
561
566
# update progress
562
- progress (_ ("Submitting" ))
567
+ progress (_ ("Submitting" if org == "submit50" else "Uploading" ))
563
568
564
569
# push branch
565
570
run ("git commit --allow-empty --message='{}'" .format (timestamp ))
571
+ commit_hash = run ("git rev-parse HEAD" )
566
572
run ("git push origin 'refs/heads/{}'" .format (branch ), password = password )
567
573
568
574
# successful submission
569
- cprint (_ ("Submitted {}! "
570
- "See https://cs50.me/submissions/{}." ).format (problem , branch ),
571
- "green" )
575
+ if org == "submit50" :
576
+ cprint (_ ("Submitted {}! See https://cs50.me/submissions." ).format (branch ),
577
+ "green" )
578
+
579
+ progress (False )
580
+ return username , commit_hash
572
581
573
582
574
583
submit .ATTRIBUTES = None
0 commit comments