def fetch(self): if self.enabled: token = AppStorage("accessToken").retrieve() response = Ghostlines('v1', token=token).applicant_roster(self.family_id) self.applicant_roster = response.json() self.set(self.applicant_roster["applicants"])
def fetch(self): if self.font.lib.has_key('pm.ghostlines.ghostlines.registry_token'): response = Ghostlines('v0.1').registry(self.font.lib['pm.ghostlines.ghostlines.registry_token']) registry = response.json() applicant_emails = [r['email_address'] for r in registry['applicants'] if not r['approved_at']] self.list.set(applicant_emails)
def send(self, sender): recipients = self.window.recipients.get() selection = [ recipients[i] for i in self.window.recipients.getSelection() ] if selection == []: selection = self.window.recipients.get() recipients = ', '.join(selection) progress = ProgressWindow('', tickCount=3, parentWindow=self.window) try: tmpdir = tempfile.mkdtemp(prefix="ghostlines") progress.update('Generating OTF') # Should be controlled which options are used somewhere filename = os.path.join(tmpdir, self.font.info.familyName + '.otf') self.font.generate(format="otf", path=filename, decompose=True, checkOutlines=True, autohint=True) progress.update('Sending via Ghostlines') with open(filename, 'rb') as otf: params = dict(otf=otf, recipients=recipients, notes=self.window.notes_field.get(), designer_email_address=self.window. email_address_field.get()) license_path = self.license_storage.retrieve() if license_path is not '' and os.path.exists(license_path): with open(license_path, 'rb') as license: filename = os.path.basename(license_path) _, extension = os.path.splitext(license_path) content_type = filetypes[extension] params['license'] = (filename, license, content_type) response = Ghostlines('v0.1').send(**params) else: response = Ghostlines('v0.1').send(**params) if response.status_code == requests.codes.created: message("{} was delivered".format(self.font.info.familyName)) else: print repr(response) message( "{} could not be delivered".format( self.font.info.familyName), "Error code: {}\n{}".format(response.status_code, response.json())) finally: progress.close()
def send(self, *_): subscribers = self.window.subscriber_info.subscribers.get() subscriber_ids = [ subscribers[i]["id"] for i in self.window.subscriber_info.subscribers.getSelection() ] notes = self.note_draft_storage.retrieve() font_family_id = self.family_id_storage.retrieve() license_path = self.license_storage.retrieve() progress = ProgressWindow('', tickCount=3, parentWindow=self.window) try: tmpdir = tempfile.mkdtemp(prefix="ghostlines") progress.update('Generating OTF') # Should be controlled which options are used somewhere otf_path = os.path.join(tmpdir, '{}.otf'.format(self.font.info.familyName)) self.font.generate(format="otf", path=otf_path, decompose=True, checkOutlines=True, autohint=True) progress.update('Sending via Ghostlines') params = dict(notes=notes, font_family_id=font_family_id) with open(otf_path, 'rb') as otf: params['otfs'] = [(os.path.basename(otf_path), otf.read(), "application/octet-stream")] if subscriber_ids: params['subscriber_ids[]'] = subscriber_ids if self.license_exists: with open(license_path, 'rb') as license: filename = os.path.basename(license_path) _, extension = os.path.splitext(license_path) content_type = filetypes[extension] params['license'] = (filename, license.read(), content_type) token = AppStorage("accessToken").retrieve() response = Ghostlines('v1', token=token).create_release(**params) if response.status_code == requests.codes.created: message("{} was delivered".format(self.font.info.familyName)) self.refresh_releases() else: ErrorMessage( "{} could not be delivered".format( self.font.info.familyName), response.json()["errors"]) finally: progress.close()
def remove_subscriber(self, sender): token = AppStorage("accessToken").retrieve() api = Ghostlines("v1", token=token) for index in self.window.subscriber_info.subscribers.getSelection(): subscriber = self.window.subscriber_info.subscribers[index] api.delete_subscriber(subscriber["id"]) self.refresh_subscribers()
def activate(self, *args): response = Ghostlines('v0.1').enable_applicants({ 'font_name': self.font.info.familyName, 'designer': self.font.info.designer }) registry = response.json() self.font.lib['pm.ghostlines.ghostlines.registry_token'] = registry['token'] self.activated = True
def enable(self, *args): token = AppStorage("accessToken").retrieve() response = Ghostlines('v1', token=token).enable_applicants_v1(self.family_id) json = response.json() if response.status_code == 201: self.applicant_roster = json self.enabled = True else: ErrorMessage("Could not enable applicants", json["errors"]).open()
def fetch(self): if self.font.lib.has_key('pm.ghostlines.ghostlines.registry_token'): response = Ghostlines('v0.1').registry( self.font.lib['pm.ghostlines.ghostlines.registry_token']) registry = response.json() applicant_emails = [ r['email_address'] for r in registry['applicants'] if not r['approved_at'] ] self.list.set(applicant_emails)
def activate(self, *args): response = Ghostlines('v0.1').enable_applicants({ 'font_name': self.font.info.familyName, 'designer': self.font.info.openTypeNameDesigner }) registry = response.json() self.font.lib['pm.ghostlines.ghostlines.registry_token'] = registry[ 'token'] self.activated = True
def create_subscriber(self, *args): name = self.window.sheet.name.get() email_address = self.window.sheet.email_address.get() token = AppStorage("accessToken").retrieve() api = Ghostlines("v1", token=token) response = api.create_subscriber(self.family_id_storage.retrieve(), name, email_address) json = response.json() if response.status_code == 201: self.refresh_subscribers() self.close_sheet() else: ErrorMessage("Couldn't create that subscriber", json["errors"])
def sign_in(self, _): email_address = self.window.email_field.get() password = self.window.password_field.get() response = Ghostlines('v1').authenticate(email_address, password) json = response.json() if response.status_code == 201: # Success! account = json['account'] token = json['token'] AppStorage('accessToken').store(token) self.success_window(self.__class__, account=account).open() self.window.close() else: ErrorMessage('Sign In Error', json['errors']).open()
def send(self, sender): recipients = ', '.join(self.window.recipients.get()) progress = ProgressWindow('', tickCount=3, parentWindow=self.window) try: tmpdir = tempfile.mkdtemp(prefix="ghostlines") progress.update('Generating OTF') # Should be controlled which options are used somewhere filename = os.path.join(tmpdir, self.font.info.familyName + '.otf') self.font.generate(filename, "otf", decompose=True, checkOutlines=True, autohint=True) progress.update('Sending via Ghostlines') with open(filename, 'rb') as otf: params = dict( otf=otf, recipients=recipients, notes=self.window.notes_field.get(), designer_email_address=self.window.email_address_field.get() ) license_path = self.license_storage.retrieve() if license_path is not '' and os.path.exists(license_path): with open(license_path, 'rb') as license: filename = os.path.basename(license_path) _, extension = os.path.splitext(license_path) content_type = filetypes[extension] params['license'] = (filename, license, content_type) response = Ghostlines('v0.1').send(**params) else: response = Ghostlines('v0.1').send(**params) if response.status_code == requests.codes.created: message("{} was delivered".format(self.font.info.familyName)) else: print repr(response) message("{} could not be delivered".format(self.font.info.familyName), "Error code: {}\n{}".format(response.status_code, response.json())) finally: progress.close()
def approve_applicant(self, *args): selected_applicants = [self.list[i] for i in self.list.getSelection()] for applicant in selected_applicants: token = AppStorage("accessToken").retrieve() Ghostlines('v1', token=token).approve_applicant(applicant["id"]) self.after_approve() self.fetch()
def approve_applicant(self, *args): selected_applicants = [self.list[i] for i in self.list.getSelection()] for applicant in selected_applicants: Ghostlines('v0.1').approve( self.font.lib['pm.ghostlines.ghostlines.registry_token'], applicant) self.after_approve(applicant) self.fetch()
def create(self, _): token = AppStorage('accessToken').retrieve() api = Ghostlines("v1", token=token) name = self.window.family_name.get() designer_name = self.window.designer_name.get() response = api.create_font_family(name, designer_name) json = response.json() if response.status_code == 201: family_id_storage = LibStorage(self.font.lib, "fontFamilyId") family_id_storage.store(json["id"]) if self.font.info.openTypeNameDesigner is None: self.font.info.openTypeNameDesigner = designer_name if self.font.info.familyName is None: self.font.info.familyName = name self.success_window(self.font).open() self.window.close() else: ErrorMessage('Could not create a font family', json['errors']).open()
def migrate(self, *_): token = AppStorage("accessToken").retrieve() api = Ghostlines("v1", token=token) response = api.migrate(list(self.recipients), self.font.info.familyName, self.font.info.openTypeNameDesigner, self.roster_token) json = response.json() if response.status_code == 201: LibStorage(self.font.lib, "fontFamilyId").store(json["id"]) expired_keys = [ 'pm.ghostlines.ghostlines.registry_token', 'pm.ghostlines.ghostlines.recipients', 'pm.ghostlines.ghostlines.designer_email_address' ] for key in expired_keys: if key in self.font.lib: del self.font.lib[key] old_note_storage = LibStorage(self.font.lib, "release_notes_draft") old_license_storage = LibStorage(self.font.lib, "license_filepath") LibStorage(self.font.lib, "releaseNotesDraft").store( old_note_storage.retrieve(default=None)) LibStorage(self.font.lib, "licenseFilepath").store( old_license_storage.retrieve(default=None)) old_note_storage.store(None) old_license_storage.store(None) from ghostlines.windows.release_window import ReleaseWindow self.window.close() ReleaseWindow(self.font).open() else: ErrorMessage("Oops", json["errors"])
def open_registration_page(self, *args): response = Ghostlines('v0.1').registry(self.font.lib['pm.ghostlines.ghostlines.registry_token']) registry = response.json() webbrowser.open(registry['url'])
def account(self): token = AppStorage('accessToken').retrieve() response = Ghostlines("v1", token=token).account() return response.json()
def font_family(self): token = AppStorage("accessToken").retrieve() return Ghostlines("v1", token=token).font_family( self.family_id_storage.retrieve()).json()
def refresh_font_family(self, *args): token = AppStorage("accessToken").retrieve() api = Ghostlines("v1", token=token) self.font_family = api.font_family( self.family_id_storage.retrieve()).json() self.resize_window_for_releases()
def open_registration_page(self, *args): response = Ghostlines('v0.1').registry( self.font.lib['pm.ghostlines.ghostlines.registry_token']) registry = response.json() webbrowser.open(registry['url'])