66# Distributed under the terms of the GNU General Public License (GPL).
77import time
88import os
9+ import traceback
910
1011from .functions import setLocalPath , showCommitDialog , logInPavlovia , noGitWarning
1112from psychopy .localization import _translate
1213from psychopy .projects import pavlovia
14+ from psychopy import logging
1315
1416try :
1517 import git
@@ -161,6 +163,8 @@ def submitChanges(self, evt=None):
161163
162164 self .EndModal (wx .ID_OK )
163165 pavlovia .knownProjects .save ()
166+ self .project .getRepo (forceRefresh = True )
167+ self .parent .project = self .project
164168
165169 def onBrowseLocal (self , evt = None ):
166170 newPath = setLocalPath (self , path = self .filename )
@@ -420,12 +424,26 @@ def syncProject(parent, project=None):
420424 # we first need to choose a location for the repository
421425 setLocalPath (parent , project )
422426 parent .Raise () # make sure that frame is still visible
427+
428+ #check that the project does exist remotely
429+ if not project .pavlovia :
430+ # project didn't exist at Pavlovia (deleted?)
431+ recreatorDlg = ProjectRecreator (parent = parent , project = project )
432+ ok = recreatorDlg .ShowModal ()
433+ if ok > 0 :
434+ project = recreatorDlg .project
435+ else :
436+ logging .error ("Failed to recreate project to sync with" )
437+ return
438+
423439 # a sync will be necessary so can create syncFrame
424440 syncFrame = SyncFrame (parent = parent , id = wx .ID_ANY , project = project )
425441
426442 if project ._newRemote :
427- # new remote, with local files, so init, add, push
428- project .newRepo (syncFrame .progHandler )
443+ # new remote so this will be a first push
444+ if project .getRepo (forceRefresh = True ) is None :
445+ # no local repo yet so create one
446+ project .newRepo (syncFrame .progHandler )
429447 # add the local files and commit them
430448 showCommitDialog (parent = parent , project = project ,
431449 initMsg = "First commit" )
@@ -435,9 +453,10 @@ def syncProject(parent, project=None):
435453 # git push -u origin master
436454 try :
437455 project .firstPush ()
456+ project ._newRemote = False
438457 except Exception as e :
439458 closeFrameWhenDone = False
440- syncFrame .syncPanel .statusAppend (e )
459+ syncFrame .syncPanel .statusAppend (traceback . format_exc () )
441460 else :
442461 # existing remote which we should clone
443462 try :
@@ -446,17 +465,20 @@ def syncProject(parent, project=None):
446465 closeFrameWhenDone = False
447466 except Exception as e :
448467 closeFrameWhenDone = False
449- syncFrame .syncPanel .statusAppend (e )
468+ syncFrame .syncPanel .statusAppend (traceback . format_exc () )
450469 # check for anything to commit before pull/push
451470 outcome = showCommitDialog (parent , project )
452471 # 0=nothing to do, 1=OK, -1=cancelled
453472 if outcome == - 1 : # user cancelled
454473 return - 1
455474 try :
456- project .sync (syncFrame .syncPanel , syncFrame .progHandler )
457- except Exception as e :
475+ status = project .sync (syncFrame .syncPanel , syncFrame .progHandler )
476+ if status == - 1 :
477+ syncFrame .syncPanel .statusAppend ("Couldn't sync" )
478+ except Exception : # not yet sure what errors might occur
479+ # send the
458480 closeFrameWhenDone = False
459- syncFrame .syncPanel .statusAppend (e )
481+ syncFrame .syncPanel .statusAppend (traceback . format_exc () )
460482
461483 wx .Yield ()
462484 project ._lastKnownSync = time .time ()
@@ -498,3 +520,55 @@ def __init__(self, project, *args, **kwargs):
498520
499521 self .SetSizerAndFit (mainSizer )
500522 self .Layout ()
523+
524+
525+ class ProjectRecreator (wx .Dialog ):
526+ """Use this Dlg to handle the case of a missing (deleted?) remote project
527+ """
528+
529+ def __init__ (self , project , parent , * args , ** kwargs ):
530+ wx .Dialog .__init__ (self , parent , * args , ** kwargs )
531+ self .parent = parent
532+ self .project = project
533+ existingName = project .name
534+ msgText = _translate ("points to a remote that doesn't exist (deleted?)." )
535+ msgText += (" " + _translate ("What shall we do?" ))
536+ msg = wx .StaticText (self , label = "{} {}" .format (existingName , msgText ))
537+ choices = [_translate ("(Re)create a project" ),
538+ "{} ({})" .format (_translate ("Point to an different location" ),
539+ _translate ("not yet supported" )),
540+ _translate ("Forget the local git repository (deletes history keeps files)" ),
541+ _translate ("Do nothing and abort the sync" )]
542+ self .radioCtrl = wx .RadioBox (self , label = 'RadioBox' , choices = choices ,
543+ majorDimension = 1 )
544+ self .radioCtrl .EnableItem (1 , False )
545+ self .radioCtrl .EnableItem (2 , False )
546+
547+ mainSizer = wx .BoxSizer (wx .VERTICAL )
548+ mainSizer .Add (msg , 1 , wx .ALL , 5 )
549+ mainSizer .Add (self .radioCtrl , 1 , wx .ALL , 5 )
550+ mainSizer .Add (wx .Button (self , id = wx .ID_OK , label = _translate ("OK" )),
551+ 1 , wx .ALL | wx .ALIGN_RIGHT , 5 )
552+
553+ self .SetSizerAndFit (mainSizer )
554+ self .Layout ()
555+
556+ def ShowModal (self ):
557+ if wx .Dialog .ShowModal (self ) == wx .ID_OK :
558+ choice = self .radioCtrl .GetSelection ()
559+ if choice == 0 :
560+ editor = ProjectEditor (parent = self .parent ,
561+ localRoot = self .project .localRoot )
562+ if editor .ShowModal () == wx .ID_OK :
563+ self .project = editor .project
564+ return 1 # success!
565+ else :
566+ return - 1 # user cancelled
567+ elif choice == 1 :
568+ raise NotImplementedError ("We don't yet support redirecting "
569+ "your project to a new location." )
570+ elif choice == 2 :
571+ raise NotImplementedError ("Deleting the local git repo is not "
572+ "yet implemented" )
573+ else :
574+ return - 1
0 commit comments