def __init__(self): self._setupSystemLogging() self.logger: Logger = getLogger(__name__) Preferences.determinePreferencesLocation() configFile: Path = Path(Preferences.getPreferencesLocation()) # # Will create a default one if necessary # if configFile.exists() is False: self._preferences = Preferences()
def __init__(self): self.logger: Logger = getLogger(__name__) self._preferences: Preferences = Preferences() self._errorsHandled: HandledErrors = HandledErrors([INVALID_TEMP_ID])
def getProjectTasks(): api_token: str = Preferences().todoistApiToken todoist: TodoistAPI = TodoistAPI(api_token) todoist.sync() projects: List[Project] = todoist.state['projects'] mockProject: Project = cast(Project, None) for project in projects: project = cast(Project, project) projectName: str = project["name"] if projectName == 'MockProject': mockProject = project break mockProjectId: int = mockProject['id'] print(f'{mockProjectId=}') dataItems: Dict[str, Item] = todoist.projects.get_data(project_id=mockProjectId) # noinspection PyTypeChecker items: List[Item] = dataItems['items'] for item in items: print(f'{item["content"]=} {item["id"]=} {item["parent_id"]=}')
def __init__(self, parent: Window, wxID: int, title: str): self._preferences: Preferences = Preferences() appSize: Size = Size(self._preferences.startupWidth, self._preferences.startupHeight) super().__init__(parent=parent, id=wxID, title=title, size=appSize, style=DEFAULT_FRAME_STYLE | FRAME_EX_METAL) self.logger: Logger = getLogger(__name__) self._status = self.CreateStatusBar() self._status.SetStatusText('Ready!') self._createApplicationMenuBar() self._githubPanel, self._todoistPanel = self._createApplicationContentArea( ) # self.SetThemeEnabled(True) x, y = self._preferences.appStartupPosition if x == str(Preferences.NO_DEFAULT_X) or y == str( Preferences.NO_DEFAULT_Y): self.Center(BOTH) # Center on the screen else: appPosition: Tuple[int, int] = self._preferences.appStartupPosition self.SetPosition(pt=appPosition) self.Bind(EVT_CLOSE, self.Close) self.Bind(EVT_REPOSITORY_SELECTED, self._onRepositorySelected) self.Bind(EVT_ISSUES_SELECTED, self._onIssuesSelected)
def setUp(self): self.logger: Logger = TestTodoistAdapterReal.clsLogger super().setUp() preferences: Preferences = Preferences() self._adapter: TodoistAdapter = TodoistAdapter( apiToken=preferences.todoistApiToken)
def testTodoistApiToken(self): preferences: Preferences = Preferences() preferences.todoistApiToken = '77777' self.assertEqual('77777', preferences.todoistApiToken, 'Uh oh, token did not change')
def addSimpleTask(): api_token: str = Preferences().todoistApiToken todoist: TodoistAPI = TodoistAPI(api_token) todoist.add_item("Item1") todoist.sync() todoist.commit()
def __init__(self, apiToken: str): """ Initialize common protected properties Args: apiToken: The login token for the todoist API """ self._todoist: TodoistAPI = TodoistAPI(apiToken) self._preferences: Preferences = Preferences() self._devTasks: Tasks = Tasks([])
def OnInit(self): TestBase.setUpLogging() self.logger: Logger = getLogger('TestADialog') frameTop: Frame = Frame(parent=None, id=TestADialog.FRAME_ID, title="Test A Dialog", size=(600, 400), style=DEFAULT_FRAME_STYLE) # frameTop.Show(False) Preferences.determinePreferencesLocation() self.SetTopWindow(frameTop) self._frameTop = frameTop self.initTest() return True
def _backupPreferences(self): preferencesFileName: str = Preferences.getPreferencesLocation() source: str = preferencesFileName target: str = f"{preferencesFileName}{TestPreferences.BACKUP_SUFFIX}" if osPath.exists(source): try: copyfile(source, target) except IOError as e: self.logger.error(f'Unable to copy file. {e}')
def _onConfigure(self, event: CommandEvent): dlg: DlgConfigure = DlgConfigure(self) if dlg.ShowModal() == OK: preferences: Preferences = Preferences() todoistToken: str = preferences.todoistApiToken githubToken: str = preferences.githubApiToken gitHubUserName: str = preferences.githubUserName self.logger.debug( f'{todoistToken=} - {githubToken=} {gitHubUserName=}')
def testRealAPI(self): ci: CloneInformation = CloneInformation() ci.repositoryTask = 'MockUser/MockRepo' ci.milestoneNameTask = 'MockMilestone' ci.tasksToClone = self._createTasksToClone() preferences: Preferences = Preferences() adapter: TodoistAdapter = TodoistAdapter( apiToken=preferences.todoistApiToken) adapter.createTasks(info=ci, progressCb=self._sampleCallback)
def __init__(self, parent, *args, **kwargs): """ This constructor creates and instance of the preferences class for use by the subclasses; Additionally, it immediately calls the methods necessary to populate the container with the implementation controls. """ super().__init__(parent, *args, **kwargs) self._preferences: Preferences = Preferences() self._createControls() self._setControlValues()
def _restoreBackup(self): preferencesFileName: str = Preferences.getPreferencesLocation() source: str = f"{preferencesFileName}{TestPreferences.BACKUP_SUFFIX}" target: str = preferencesFileName if osPath.exists(source): try: copyfile(source, target) except IOError as e: self.logger.error(f"Unable to copy file. {e}") osRemove(source) else: osRemove(target)
def __handleAuthenticationError(self, event: CommandEvent): eDlg = GenericMessageDialog(self, 'The supplied todoist token is invalid', "", agwStyle=ICON_ERROR | OK) eDlg.ShowModal() eDlg.Destroy() with DlgConfigure(self) as aDlg: cDlg: DlgConfigure = cast(DlgConfigure, aDlg) if cDlg.ShowModal() == OK: # The following 2 already defined in init self._apiToken = Preferences().todoistApiToken self._todoistAdapter = TodoistAdapter(self._apiToken) self._onCreateTaskClicked(event) # Dang I hate recursion
def getProjects(): api_token: str = Preferences().todoistApiToken todoist: TodoistAPI = TodoistAPI(api_token) todoist.sync() projects = todoist.state['projects'] for project in projects: projectName: str = project["name"] projectId: int = project['id'] print(f'{projectName:12} - {projectId=}') try: if projectName == 'PyUt': todoist.projects.delete(projectId) todoist.sync() todoist.commit() except SyncError as se: print(f'{se=}')
def __init__(self, parent: Window): super().__init__(parent) self.SetBackgroundColour(self.backgroundColor) self.logger: Logger = getLogger(__name__) preferences: Preferences = Preferences() self._preferences: Preferences = preferences self._selectedSimpleGitIssues: AbbreviatedGitIssues = [] self._githubAdapter: GithubAdapter = GithubAdapter( userName=preferences.githubUserName, authenticationToken=preferences.githubApiToken) contentSizer: BoxSizer = self._layoutContent() # noinspection PyUnresolvedReferences self.SetSizer(contentSizer) self.Fit()
def initTest(self): with DlgConfigure(self._frameTop) as dlg: dlg: DlgConfigure = cast(DlgConfigure, dlg) if dlg.ShowModal() == OK: preferences: Preferences = Preferences() # self._frameTop.Close(force=True) self.logger.info(f'{preferences.todoistApiToken=}') self.logger.info(f'{preferences.githubUserName=}') self.logger.info(f'{preferences.githubApiToken=}') else: self.logger.warning(f'Cancelled') # self._frameTop.Close(force=True) # with DlgHelp(self._frameTop) as dlg: # dlg: DlgHelp = cast(DlgHelp, dlg) # if dlg.ShowModal() == OK: # self.logger.warning('Clicked Ok') # else: # self.logger.warning(f'Cancelled') self.logger.info(f"After dialog show") sysExit() # brutal !!
def testAddTaskAsHyperlink(self): # markdown Link format # [here](https://github.com/hasii2011/gittodoistclone/wiki/How-to-use-gittodoistclone) hyperLinkedTask: TaskInfo = TaskInfo() hyperLinkedTask.gitIssueName = f'I am linked' hyperLinkedTask.gitIssueURL = 'https://hsanchezii.wordpress.com' ci: CloneInformation = CloneInformation() ci.repositoryTask = 'MockUser/MockRepo' ci.milestoneNameTask = 'MockMilestone' ci.tasksToClone = [hyperLinkedTask] preferences: Preferences = Preferences() savedOption: GitHubURLOption = preferences.githubURLOption preferences.githubURLOption = GitHubURLOption.HyperLinkedTaskName adapter: TodoistAdapter = self._adapter adapter.createTasks(ci, self._sampleCallback) preferences.githubURLOption = savedOption
def __init__(self, parent: Window): super().__init__(parent) self.SetBackgroundColour(self.backgroundColor) self.logger: Logger = getLogger(__name__) contentSizer: BoxSizer = self._layoutContent() # noinspection PyUnresolvedReferences self.SetSizer(contentSizer) self.Fit() self._cloneInformation: CloneInformation = cast(CloneInformation, None) self._preferences: Preferences = Preferences() self._apiToken: str = self._preferences.todoistApiToken if self._preferences.singleTodoistProject is True: self._todoistAdapter: AbstractTodoistAdapter = TodoistAdapterSingleProject( apiToken=self._apiToken) else: self._todoistAdapter = TodoistAdapter(self._apiToken)
def addTaskToProject(): api_token: str = Preferences().todoistApiToken todoist: TodoistAPI = TodoistAPI(api_token) todoist.sync() projects = todoist.state['projects'] projectId = -1 for project in projects: projectName: str = project["name"] if projectName == 'Development': projectId = project['id'] print(f'{projectName=} - {projectId=}') break taskItem = todoist.items.add('I am an external Task', project_id=projectId) taskItem.update(priority=1) todoist.sync() todoist.commit()
def setUpClass(cls): TestTodoistAdapterBase.setUpClass() TestTodoistAdapterReal.clsLogger = getLogger(__name__) Preferences.determinePreferencesLocation()
from typing import Dict from typing import List from typing import cast from todoist.api import SyncError from todoist.api import TodoistAPI from todoist.models import Item from todoist.models import Project from gittodoistclone.general.Preferences import Preferences Preferences.determinePreferencesLocation() # Used for prototyping def addSimpleTask(): api_token: str = Preferences().todoistApiToken todoist: TodoistAPI = TodoistAPI(api_token) todoist.add_item("Item1") todoist.sync() todoist.commit() def addTaskToProject(): api_token: str = Preferences().todoistApiToken
def testSingleTodoistProjectTrue(self): preferences: Preferences = Preferences() preferences.singleTodoistProject = True self.assertTrue(preferences.singleTodoistProject, "Did not change to 'True'")
def testSingleTodoistProjectFalse(self): preferences: Preferences = Preferences() preferences.singleTodoistProject = False self.assertFalse(preferences.singleTodoistProject, "Did not change to 'False'")
from github import Github from github.Milestone import Milestone from github.NamedUser import NamedUser from gittodoistclone.general.Preferences import Preferences Preferences.determinePreferencesLocation() INTEGRATION_TOKEN: str = Preferences().githubApiToken USERNAME: str = 'hasii2011' # Used for prototyping def getIssuesInRepos(): g = Github(INTEGRATION_TOKEN) user: NamedUser = g.get_user(USERNAME) print(f'{user=}') repo = g.get_repo('hasii2011/PyUt') print(f'{repo=}') open_issues = repo.get_issues(state='open') print(f'**** list of milestone -- Release 7.0 issues') for issue in open_issues: mileStone: Milestone = issue.milestone if mileStone is not None and mileStone.title == 'Release 7.0': print(f'{issue=}')
def testNoPreferencesExist(self): preferences: Preferences = Preferences() self.assertIsNotNone(preferences, 'Ouch. Was not created')
def setUpClass(cls): TestBase.setUpLogging() TestPreferences.clsLogger = getLogger(__name__) Preferences.determinePreferencesLocation() # Must do this once
def __setTodoistProjectNameToEmpty(self): preferences: Preferences = Preferences() preferences.todoistProjectName = None