def static_init(cls): """init collection copy""" cls.adapters = [] cls.filesystem_folder = expanduser( cls.configuration.get('storage', 'filesystem_folder')) if cls.configuration.has_option('storage', 'remind_file'): tz = None if cls.configuration.has_option('storage', 'remind_timezone'): tz = timezone( cls.configuration.get('storage', 'remind_timezone')) month = cls.configuration.getint('storage', 'remind_lookahead_month', fallback=15) cls.adapters.append( Remind(cls.configuration.get('storage', 'remind_file'), tz, month=month)) if cls.configuration.has_option('storage', 'abook_file'): cls.adapters.append( Abook(cls.configuration.get('storage', 'abook_file'))) if cls.configuration.has_option('storage', 'task_folder'): cls.adapters.append( IcsTask(cls.configuration.get('storage', 'task_folder')))
def submit_info(self): file_size = os.path.getsize(self.file_name) file_mtime = os.path.getmtime(self.file_name) pro_name = self.file_path.split('/')[1] csv_path = os.path.join(self.csv_path, '%s.csv' % pro_name) with open(csv_path, 'a+') as f: con_write = self.file_name, file_size, file_mtime con_read = set(f.readlines()) con_write = str(con_write) + '\n' if con_write not in con_read: f.write(con_write) else: Remind().remind_ask()
def main(): """Command line tool to download from CalDAV to Remind""" parser = ArgumentParser(description='Command line tool to download from CalDAV to Remind') parser.add_argument('-d', '--delete', action='store_true', help='Delete old events') parser.add_argument('-r', '--davurl', required=True, help='The URL of the CalDAV server') parser.add_argument('-u', '--davuser', help='The username for the CalDAV server') parser.add_argument('-p', '--davpass', help='The password for the CalDAV server') parser.add_argument('-i', '--insecure', action='store_true', help='Ignore SSL certificate') parser.add_argument('remfile', nargs='?', default=expanduser('~/.reminders'), help='The Remind file to process (default: ~/.reminders)') args = parser.parse_args() # create empty file if it does not exist open(args.remfile, 'a') rem = Remind(args.remfile) ldict = set(rem.get_uids()) if args.davuser and args.davpass: user = args.davuser passwd = args.davpass else: try: (user, _, passwd) = netrc().authenticators(urlparse(args.davurl).netloc) except (IOError, TypeError): if not args.davuser: print('dav2rem: Error, argument -u/--davuser or netrc is required') return 1 user = args.davuser try: from keyring import get_password passwd = get_password(urlparse(args.davurl).netloc, user) except ImportError: passwd = None if not passwd: passwd = getpass() client = DAVClient(args.davurl, username=user, password=passwd, ssl_verify_cert=not args.insecure) calendar = Calendar(client, args.davurl) rdict = {splitext(basename(event.canonical_url))[0].replace('%40', '@'): event for event in calendar.events()} if args.delete: local = ldict - rdict.keys() for uid in local: rem.remove(uid) remote = rdict.keys() - ldict for uid in remote: vevent = rdict[uid] rem.append_vobject(readOne(vevent.data))
def submit(self, Uptask): self.submit_info() up_name = self.file_name.split('/')[-1] file_number = self.file_path.split('_')[0][-9:] if Uptask == 'Ready_render1' or Uptask == 'Ready_render2': cmd = 'export PATH=/Public/Support/Thinkbox/Deadline8/bin:$PATH && deadlinecommand -SubmitCommandLineJob -executable "/usr/bin/python" -arguments "%s -r -q <QUOTE>%s<QUOTE>" -chunksize 1 -priority 100 -name "%s" -prop MachineLimit=5' % ( self.ray_py_file, self.file_name, up_name) elif Uptask == 'Local_render1' or Uptask == 'Local_render2': cmd = 'export PATH=/Public/Support/Thinkbox/Deadline8/bin:$PATH && deadlinecommand -SubmitCommandLineJob -executable "/usr/bin/python" -arguments "%s -r <QUOTE>%s<QUOTE>" -chunksize 1 -priority 100 -name "%s" -prop MachineLimit=5' % ( self.ray_py_file, self.file_name, up_name) elif Uptask == 'Cloud_render1' or Uptask == 'Cloud_render2': cmd = 'export PATH=/Public/Support/Thinkbox/Deadline8/bin:$PATH && deadlinecommand -SubmitCommandLineJob -executable "/usr/bin/python" -arguments "%s -a -u -s <QUOTE>%s<QUOTE>" -chunksize 1 -pool upload_submit_pool -group upload_submit_group -priority 100 -name "%s" -prop MachineLimit=5' % ( self.ray_py_file, self.file_name, up_name) popen_cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) Remind().remind_start(file_number) while True: line = popen_cmd.stdout.readline() line = line.strip() if not line == '': print line if 'successfully' in line: Remind().remind_success(file_number) # else: # Remind().remind_fail(line, file_number) if line == '' and popen_cmd.poll() != None: break # 'export PATH=/Public/Support/Thinkbox/Deadline8/bin:$PATH && deadlinecommand -SubmitCommandLineJob -executable "/usr/bin/python" -arguments "%s -r -q <QUOTE>%s<QUOTE>" -chunksize 1 -priority 100 -name "%s" -prop MachineLimit=5' % ( # 'export PATH=/Public/Support/Thinkbox/Deadline8/bin:$PATH && deadlinecommand -SubmitCommandLineJob -executable "/usr/bin/python" -arguments "%s -r <QUOTE>%s<QUOTE>" -chunksize 1 -priority 100 -name "%s" -prop MachineLimit=5' % ( # 'export PATH=/Public/Support/Thinkbox/Deadline8/bin:$PATH && deadlinecommand -SubmitCommandLineJob -executable "/usr/bin/python" -arguments "%s -a -u -s <QUOTE>%s<QUOTE>" -chunksize 1 -pool upload_submit_pool -group upload_submit_group -priority 100 -name "%s" -prop MachineLimit=5' % ( # 'export PATH=/Public/Support/Thinkbox/Deadline8/bin:$PATH && deadlinecommand -SubmitCommandLineJob -executable "/usr/bin/python" -arguments "%s -r -q <QUOTE>%s<QUOTE>" -chunksize 1 -priority 100 -name "%s" -prop MachineLimit=5'
def main(): """Command line tool to download from CalDAV to Remind""" parser = ArgumentParser(description='Command line tool to download from CalDAV to Remind') parser.add_argument('-d', '--delete', action='store_true', help='Delete old events') parser.add_argument('-r', '--davurl', required=True, help='The URL of the CalDAV server') parser.add_argument('-u', '--davuser', help='The username for the CalDAV server') parser.add_argument('-p', '--davpass', help='The password for the CalDAV server') parser.add_argument('-i', '--insecure', action='store_true', help='Ignore SSL certificate') parser.add_argument('remfile', nargs='?', default=expanduser('~/.reminders'), help='The Remind file to process (default: ~/.reminders)') args = parser.parse_args() # create empty file if it does not exist open(args.remfile, 'a') rem = Remind(args.remfile) ldict = set(rem.get_uids()) if args.davuser and args.davpass: user = args.davuser passwd = args.davpass else: try: (user, _, passwd) = netrc().authenticators(urlparse(args.davurl).netloc) except (IOError, TypeError): if not args.davuser: print 'dav2rem: Error, argument -u/--davuser or netrc is required' return 1 user = args.davuser try: from keyring import get_password passwd = get_password(urlparse(args.davurl).netloc, user) except ImportError: passwd = None if not passwd: passwd = getpass() client = DAVClient(args.davurl, username=user, password=passwd, ssl_verify_cert=not args.insecure) calendar = Calendar(client, args.davurl) rdict = {splitext(basename(event.canonical_url))[0].replace('%40', '@'): event for event in calendar.events()} if args.delete: local = ldict - rdict.viewkeys() for uid in local: rem.remove(uid) remote = rdict.viewkeys() - ldict for uid in remote: vevent = rdict[uid] rem.append(vevent.data)
def __init__(self, configuration): """Initialize BaseStorage. ``configuration`` see ``radicale.config`` module. The ``configuration`` must not change during the lifetime of this object, it is kept as an internal reference. """ self.adapters = [] self.filesystem_folder = expanduser( configuration.get('storage', 'filesystem_folder')) if 'remind_file' in configuration.options('storage'): tz = None if 'remind_timezone' in configuration.options('storage'): tz = timezone(configuration.get('storage', 'remind_timezone')) month = configuration.get('storage', 'remind_lookahead_month') or 15 self.adapters.append( Remind(configuration.get('storage', 'remind_file'), tz, month=month)) if 'abook_file' in configuration.options('storage'): self.adapters.append( Abook(configuration.get('storage', 'abook_file'))) if 'task_folder' in configuration.options('storage'): task_folder = configuration.get('storage', 'task_folder') task_projects = [] if 'task_projects' in configuration.options('storage'): task_projects = configuration.get('storage', 'task_projects').split(',') task_start = configuration.get('storage', 'task_start') or True self.adapters.append( IcsTask(task_folder, task_projects=task_projects, start_task=task_start))
def main(): """Command line tool to download from CalDAV to Remind""" parser = ArgumentParser(description='Command line tool to download from CalDAV to Remind') parser.add_argument('-d', '--delete', type=bool, default=False, help='Delete old events') parser.add_argument('-r', '--davurl', required=True, help='The URL of the calDAV server') parser.add_argument('-u', '--davuser', help='The username for the calDAV server') parser.add_argument('-p', '--davpass', help='The password for the calDAV server', default=None) parser.add_argument('remfile', nargs='?', default=expanduser('~/.reminders'), help='The Remind file to process (default: ~/.reminders)') args = parser.parse_args() rem = Remind(args.remfile) ldict = set(rem.get_uids()) try: (user, _, passwd) = netrc().authenticators(urlparse(args.davurl).netloc) except (IOError, TypeError): if not args.davuser: print "dav2rem: error: argument -u/--davuser is required" return 2 user = args.davuser if args.davpass: passwd = args.davpass else: passwd = getpass() client = DAVClient(args.davurl, username=user, password=passwd) principal = client.principal() calendar = principal.calendars()[0] rdict = {splitext(basename(event.canonical_url))[0].replace('%40', '@'): event for event in calendar.events()} if args.delete: local = ldict - rdict.viewkeys() for uid in local: rem.remove(uid) remote = rdict.viewkeys() - ldict for uid in remote: vevent = rdict[uid] vevent.load() rem.append(vevent.data)
def main(): """Command line tool to upload a Remind file to CalDAV""" parser = ArgumentParser(description="Command line tool to upload a Remind file to CalDAV") parser.add_argument( "-z", "--zone", default="Europe/Berlin", help="Timezone of Remind file (default: Europe/Berlin)" ) parser.add_argument( "-s", "--startdate", type=lambda s: parse(s).date(), default=date.today() - timedelta(weeks=12), help="Start offset for remind call (default: -12 weeks)", ) parser.add_argument( "-m", "--month", type=int, default=15, help="Number of month to generate calendar beginning wit stadtdate (default: 15)", ) parser.add_argument("-d", "--delete", action="store_true", help="Delete old events") parser.add_argument("-r", "--davurl", required=True, help="The URL of the calDAV server") parser.add_argument("-u", "--davuser", help="The username for the calDAV server") parser.add_argument("-p", "--davpass", help="The password for the calDAV server", default=None) parser.add_argument( "infile", nargs="?", default=expanduser("~/.reminders"), help="The Remind file to process (default: ~/.reminders)", ) parser.add_argument( "-o", "--old", default=None, help="The old reference Remind file (entries not in the current one will be deleted from dav)", ) args = parser.parse_args() zone = gettz(args.zone) # Manually set timezone name to generate correct ical files # (python-vobject tests for the zone attribute) zone.zone = args.zone if args.infile == "-": remind = Remind(args.infile, zone, args.startdate, args.month) vobject = remind.stdin_to_vobject(stdin.read().decode("utf-8")) else: remind = Remind(args.infile, zone, args.startdate, args.month) vobject = remind.to_vobject() if hasattr(vobject, "vevent_list"): ldict = {event.uid.value: event for event in vobject.vevent_list} else: ldict = {} try: (user, _, passwd) = netrc().authenticators(urlparse(args.davurl).netloc) except (IOError, TypeError): if not args.davuser: print "rem2dav: error: argument -u/--davuser is required" return 2 user = args.davuser if args.davpass: passwd = args.davpass else: passwd = getpass() client = DAVClient(args.davurl, username=user, password=passwd) principal = client.principal() calendar = principal.calendars()[0] rdict = {splitext(basename(event.canonical_url))[0].replace("%40", "@"): event for event in calendar.events()} if args.old: old = Remind(args.old, zone, args.startdate, args.month) old_vobject = old.to_vobject() if hasattr(old_vobject, "vevent_list"): odict = {event.uid.value: event for event in old_vobject.vevent_list} intersect = rdict.viewkeys() & odict.viewkeys() rdict = {key: rdict[key] for key in intersect} else: rdict = {} local = ldict.viewkeys() - rdict.viewkeys() for uid in local: ncal = iCalendar() ncal.add(ldict[uid]) calendar.add_event(ncal.serialize()) if args.delete or args.old: remote = rdict.viewkeys() - ldict.viewkeys() for uid in remote: rdict[uid].delete()
class Collection(icalCollection): _tz = gettz(get('storage', 'remind_timezone')) # Manually set timezone name to generate correct ical files # (python-vobject tests for the zone attribute) _tz.zone = get('storage', 'remind_timezone') _remind = Remind(expanduser(get('storage', 'remind_file')), _tz) _abook = Abook(expanduser(get('storage', 'abook_file'))) @staticmethod def _abs_path(path): return join(expanduser(get("storage", "filesystem_folder")), path.replace("/", sep)) def append(self, _, text): """Append items from ``text`` to collection. If ``name`` is given, give this name to new items in ``text``. """ if 'remind' in self.path: self._remind.append(text, self._abs_path(self.path)) if 'abook' in self.path: self._abook.append(text) def remove(self, name): """Remove object named ``name`` from collection.""" if 'remind' in self.path: self._remind.remove(name, self._abs_path(self.path)) if 'abook' in self.path: self._abook.remove(name) def replace(self, name, text): """Replace content by ``text`` in collection object called ``name``.""" if 'remind' in self.path: self._remind.replace(name, text, self._abs_path(self.path)) if 'abook' in self.path: self._abook.replace(name, text) def save(self, text): """Save the text into the collection.""" pass def delete(self): """Delete the collection.""" pass @property def text(self): """Collection as plain text.""" if 'remind' in self.path: return self._remind.to_vobject(self._abs_path( self.path)).serialize().decode('utf-8') if 'abook' in self.path: return self._abook.to_vcf().decode('utf-8') return "" @classmethod def children(cls, path): """Yield the children of the collection at local ``path``.""" children = [] for filename in cls._remind.get_filesnames(): children.append(cls(filename.replace(cls._abs_path(path), path))) children.append( cls(cls._abook.filename.replace(cls._abs_path(path), path))) return children @classmethod def is_node(cls, path): """Return ``True`` if relative ``path`` is a node. A node is a WebDAV collection whose members are other collections. """ return isdir(cls._abs_path(path)) @classmethod def is_leaf(cls, path): """Return ``True`` if relative ``path`` is a leaf. A leaf is a WebDAV collection whose members are not collections. """ return isfile(cls._abs_path(path)) @property def last_modified(self): """Get the last time the collection has been modified. The date is formatted according to rfc1123-5.2.14. """ return strftime('%a, %d %b %Y %H:%M:%S +0000', gmtime(getmtime(self._abs_path(self.path)))) @property @contextmanager def props(self): """Get the collection properties.""" # On enter if 'remind' in self.path: yield { 'tag': 'VCALENDAR', 'ICAL:calendar-color': '#%06x' % (hash(basename(self.path)) % 0xffffff) } elif 'abook' in self.path: yield {'tag': 'VADDRESSBOOK'} else: yield {}
webbrowser.open(auth_uri) auth_code = raw_input('Enter the auth code: ') credentials = flow.step2_exchange(auth_code) with open(credentials_path, 'w') as f: cPickle.dump(credentials, f) http_auth = credentials.authorize(httplib2.Http()) service = discovery.build('calendar', 'v3', http=http_auth) events = service.events() # Load Remind data tz = 'Europe/Dublin' zone = gettz(tz) zone.zone = tz # Get calendar from 1990-01-01 to 15 months from today rem = Remind(args.infile, zone, startdate=date(1990, 1, 1), month=(12 * (date.today().year-1990) + (date.today().month) + 15)) vcal = rem.to_vobject() # Clear calendar page_token = None old_events = [] while True: old = events.list( calendarId=args.calID, pageToken=page_token).execute() old_events = old_events + old['items'] page_token = old.get('nextPageToken') if not page_token: break for x in old_events: if ('extendedProperties' in x and x['extendedProperties']['private']['source'] ==
def main(): """Command line tool to upload a Remind file to CalDAV""" parser = ArgumentParser( description='Command line tool to upload a Remind file to CalDAV') parser.add_argument( '-z', '--zone', default='Europe/Berlin', help='Timezone of Remind file (default: Europe/Berlin)') parser.add_argument( '-s', '--startdate', type=lambda s: parse(s).date(), default=date.today() - timedelta(weeks=12), help='Start offset for remind call (default: -12 weeks)') parser.add_argument( '-m', '--month', type=int, default=15, help= 'Number of month to generate calendar beginning wit stadtdate (default: 15)' ) parser.add_argument('-d', '--delete', action='store_true', help='Delete old events') parser.add_argument('-r', '--davurl', required=True, help='The URL of the CalDAV server') parser.add_argument('-u', '--davuser', help='The username for the CalDAV server') parser.add_argument('-p', '--davpass', help='The password for the CalDAV server') parser.add_argument('-i', '--insecure', action='store_true', help='Ignore SSL certificate') parser.add_argument( 'infile', nargs='?', default=expanduser('~/.reminders'), help='The Remind file to process (default: ~/.reminders)') parser.add_argument( '-o', '--old', default=None, help= 'The old reference Remind file (entries not in the current one will be deleted from dav)' ) args = parser.parse_args() zone = gettz(args.zone) # Manually set timezone name to generate correct ical files # (python-vobject tests for the zone attribute) zone.zone = args.zone if args.infile == '-': remind = Remind(args.infile, zone, args.startdate, args.month) vobject = remind.stdin_to_vobject(stdin.read()) else: remind = Remind(args.infile, zone, args.startdate, args.month) vobject = remind.to_vobject() if hasattr(vobject, 'vevent_list'): ldict = {event.uid.value: event for event in vobject.vevent_list} else: ldict = {} if args.davuser and args.davpass: user = args.davuser passwd = args.davpass else: try: (user, _, passwd) = netrc().authenticators(urlparse(args.davurl).netloc) except (IOError, TypeError): if not args.davuser: print( 'rem2dav: Error, argument -u/--davuser or netrc is required' ) return 1 user = args.davuser try: from keyring import get_password passwd = get_password(urlparse(args.davurl).netloc, user) except ImportError: passwd = None if not passwd: passwd = getpass() client = DAVClient(args.davurl, username=user, password=passwd, ssl_verify_cert=not args.insecure) calendar = Calendar(client, args.davurl) rdict = { splitext(basename(event.canonical_url))[0].replace('%40', '@'): event for event in calendar.events() } if args.old: old = Remind(args.old, zone, args.startdate, args.month) old_vobject = old.to_vobject() if hasattr(old_vobject, 'vevent_list'): odict = { event.uid.value: event for event in old_vobject.vevent_list } intersect = rdict.keys() & odict.keys() rdict = {key: rdict[key] for key in intersect} else: rdict = {} local = ldict.keys() - rdict.keys() for uid in local: ncal = iCalendar() ncal.add(ldict[uid]) calendar.add_event(ncal.serialize()) if args.delete or args.old: remote = rdict.keys() - ldict.keys() for uid in remote: rdict[uid].delete()