rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
post_title = os.path.basename(content_string).split('.')[0]
title = os.path.basename(content_string).split('.')[0]
def upload_posts(self, content_list, blog_title, post_title, is_draft): """Uploads posts.
post_title = 'New post'
title = 'New post'
def upload_posts(self, content_list, blog_title, post_title, is_draft): """Uploads posts.
entry = self._upload_content(post_title,
entry = self._upload_content(post_title or title,
def upload_posts(self, content_list, blog_title, post_title, is_draft): """Uploads posts.
def get_calendar_user(self, cal_name=None): """Get "user" name for one calendar.
def get_calendar_user_list(self, cal_name=None): """Get "user" name and human-readable name for one or more calendars.
def get_calendar_user(self, cal_name=None): """Get "user" name for one calendar. The "user" for a calendar is an awful misnomer for the ID for the calendar. To get events for a calendar, you can form a query with user = self.get_calendar_user('my calendar name') if user: query = gdata.calendar.CalendarEventQuery(user=...
user = self.get_calendar_user('my calendar name') if user: query = gdata.calendar.CalendarEventQuery(user=user)
cal_list = self.get_calendar_user_list('my calendar name') if cal_list: query = gdata.calendar.CalendarEventQuery(user=cal_list[0].user)
def get_calendar_user(self, cal_name=None): """Get "user" name for one calendar. The "user" for a calendar is an awful misnomer for the ID for the calendar. To get events for a calendar, you can form a query with user = self.get_calendar_user('my calendar name') if user: query = gdata.calendar.CalendarEventQuery(user=...
uri of the default / main calendar.
an instance representing only the default / main calendar.
def get_calendar_user(self, cal_name=None): """Get "user" name for one calendar. The "user" for a calendar is an awful misnomer for the ID for the calendar. To get events for a calendar, you can form a query with user = self.get_calendar_user('my calendar name') if user: query = gdata.calendar.CalendarEventQuery(user=...
Single CalendarEntry, or None of there were no matches for cal_name.
A list of Calendar instances, or None of there were no matches for cal_name.
def get_calendar_user(self, cal_name=None): """Get "user" name for one calendar. The "user" for a calendar is an awful misnomer for the ID for the calendar. To get events for a calendar, you can form a query with user = self.get_calendar_user('my calendar name') if user: query = gdata.calendar.CalendarEventQuery(user=...
import urllib if not cal_name or cal_name == 'default': return 'default'
if not cal_name: return [Calendar(user='default', name=self.email)]
def get_calendar_user(self, cal_name=None): """Get "user" name for one calendar. The "user" for a calendar is an awful misnomer for the ID for the calendar. To get events for a calendar, you can form a query with user = self.get_calendar_user('my calendar name') if user: query = gdata.calendar.CalendarEventQuery(user=...
cal = self.GetSingleEntry('/calendar/feeds/default/allcalendars/full', cal_name, converter=gdata.calendar.CalendarListFeedFromString) if cal: return urllib.unquote(cal.content.src.split('/')[-3]) else: return None GetCalendarUser = get_calendar_user
cal_list = self.GetEntries('/calendar/feeds/default/allcalendars/full', title=cal_name, converter=gdata.calendar.CalendarListFeedFromString) if cal_list: return [Calendar(cal) for cal in cal_list] return None GetCalendarUserList = get_calendar_user_list
def get_calendar_user(self, cal_name=None): """Get "user" name for one calendar. The "user" for a calendar is an awful misnomer for the ID for the calendar. To get events for a calendar, you can form a query with user = self.get_calendar_user('my calendar name') if user: query = gdata.calendar.CalendarEventQuery(user=...
title=None, query=None, max_results=100,
title=None, query=None, max_results=1000,
def get_events(self, calendar_user, start_date=None, end_date=None, title=None, query=None, max_results=100, expand_recurrence=True): """Get events. Keyword arguments: calendar_user: "user" of the calendar to get events for. See get_calendar_user. start_date: Start date of the event(s). Must follow the RFC 3339 timest...
See get_calendar_user.
See get_calendar_user_list.
def get_events(self, calendar_user, start_date=None, end_date=None, title=None, query=None, max_results=100, expand_recurrence=True): """Get events. Keyword arguments: calendar_user: "user" of the calendar to get events for. See get_calendar_user. start_date: Start date of the event(s). Must follow the RFC 3339 timest...
cal_user = client.get_calendar_user(options.cal) if not cal_user:
cal_user_list = client.get_calendar_user_list(options.cal) if not cal_user_list:
def _run_list(client, options, args): cal_user = client.get_calendar_user(options.cal) if not cal_user: print 'No calendar matches "' + options.cal + '"' return dates = get_start_and_end(options.date) entries = client.get_events(cal_user, start_date=dates[2], end_date=dates[3], title=options.title, query=options.query)...
entries = client.get_events(cal_user, start_date=dates[2], end_date=dates[3], title=options.title, query=options.query) if args: style_list = args[0].split(',') else: style_list = googlecl.get_config_option(SECTION_HEADER, 'list_style').split(',') for entry in entries: print googlecl.service.entry_to_string(entry, styl...
for cal in cal_user_list: print '' print '[' + str(cal) + ']' entries = client.get_events(cal.user, start_date=dates[2], end_date=dates[3], title=options.title, query=options.query) if args: style_list = args[0].split(',') else: style_list = googlecl.get_config_option(SECTION_HEADER, 'list_style').split(',') for entry...
def _run_list(client, options, args): cal_user = client.get_calendar_user(options.cal) if not cal_user: print 'No calendar matches "' + options.cal + '"' return dates = get_start_and_end(options.date) entries = client.get_events(cal_user, start_date=dates[2], end_date=dates[3], title=options.title, query=options.query)...
cal_user = client.get_calendar_user(options.cal) if not cal_user:
cal_user_list = client.get_calendar_user_list(options.cal) if not cal_user_list:
def _run_list_today(client, options, args): cal_user = client.get_calendar_user(options.cal) if not cal_user: print 'No calendar matches "' + options.cal + '"' return start_date, end_date = _tomorrowize() entries = client.get_events(cal_user, start_date=start_date, end_date=end_date, title=options.title, query=options....
entries = client.get_events(cal_user, start_date=start_date, end_date=end_date, title=options.title, query=options.query) if args: style_list = args[0].split(',') else: style_list = googlecl.get_config_option(SECTION_HEADER, 'list_style').split(',') for entry in entries: print googlecl.service.entry_to_string(entry, st...
for cal in cal_user_list: print '' print '[' + str(cal) + ']' entries = client.get_events(cal.user, start_date=start_date, end_date=end_date, title=options.title, query=options.query) if args: style_list = args[0].split(',') else: style_list = googlecl.get_config_option(SECTION_HEADER, 'list_style').split(',') for ent...
def _run_list_today(client, options, args): cal_user = client.get_calendar_user(options.cal) if not cal_user: print 'No calendar matches "' + options.cal + '"' return start_date, end_date = _tomorrowize() entries = client.get_events(cal_user, start_date=start_date, end_date=end_date, title=options.title, query=options....
cal_user = client.get_calendar_user(options.cal) if not cal_user:
cal_user_list = client.get_calendar_user_list(options.cal) if not cal_user_list:
def _run_add(client, options, args): cal_user = client.get_calendar_user(options.cal) if not cal_user: print 'No calendar matches "' + options.cal + '"' return client.quick_add_event(args, cal_user)
client.quick_add_event(args, cal_user)
for cal in cal_user_list: client.quick_add_event(args, cal.user)
def _run_add(client, options, args): cal_user = client.get_calendar_user(options.cal) if not cal_user: print 'No calendar matches "' + options.cal + '"' return client.quick_add_event(args, cal_user)
cal_user = client.get_calendar_user(options.cal) if not cal_user:
cal_user_list = client.get_calendar_user_list(options.cal) if not cal_user_list:
def _run_delete(client, options, args): cal_user = client.get_calendar_user(options.cal) if not cal_user: print 'No calendar matches "' + options.cal + '"' return dates = get_start_and_end(options.date) events = client.get_events(cal_user, start_date=dates[2], end_date=dates[3], title=options.title, query=options.query...
events = client.get_events(cal_user, start_date=dates[2], end_date=dates[3], title=options.title, query=options.query, expand_recurrence=False) try: client.delete_events(events, options.date, cal_user) except EventsNotFound: print 'No events found that match your options!'
for cal in cal_user_list: print 'For calendar ' + str(cal) events = client.get_events(cal.user, start_date=dates[2], end_date=dates[3], title=options.title, query=options.query, expand_recurrence=False) try: client.delete_events(events, options.date, cal.user) except EventsNotFound: print 'No events found that match yo...
def _run_delete(client, options, args): cal_user = client.get_calendar_user(options.cal) if not cal_user: print 'No calendar matches "' + options.cal + '"' return dates = get_start_and_end(options.date) events = client.get_events(cal_user, start_date=dates[2], end_date=dates[3], title=options.title, query=options.query...
err.args[0].reason, err.args[0].body)
err.args[0], err.args[1])
def insert_photo_list(self, album, photo_list, tags=''): """Insert photos into an album. Keyword arguments: album: The album entry of the album getting the photos. photo_list: A list of paths, each path a picture on the local host. tags: Text of the tags to be added to each photo, e.g. 'Islands, Vacation' (Default '')...
format = '%(message)s'
msg_format = '%(message)s'
def setup_logger(options): """Setup the global (root, basic) configuration for logging.""" format = '%(message)s' if options.debug: level = logging.DEBUG format = '%(levelname)s:%(name)s:%(message)s' elif options.verbose: level = logging.DEBUG elif options.quiet: level = logging.ERROR else: level = logging.INFO logging...
format = '%(levelname)s:%(name)s:%(message)s'
msg_format = '%(levelname)s:%(name)s:%(message)s'
def setup_logger(options): """Setup the global (root, basic) configuration for logging.""" format = '%(message)s' if options.debug: level = logging.DEBUG format = '%(levelname)s:%(name)s:%(message)s' elif options.verbose: level = logging.DEBUG elif options.quiet: level = logging.ERROR else: level = logging.INFO logging...
logging.basicConfig(level=level, format=format)
logging.basicConfig(level=level, format=msg_format)
def setup_logger(options): """Setup the global (root, basic) configuration for logging.""" format = '%(message)s' if options.debug: level = logging.DEBUG format = '%(levelname)s:%(name)s:%(message)s' elif options.verbose: level = logging.DEBUG elif options.quiet: level = logging.ERROR else: level = logging.INFO logging...
client.Update(e, mediasource)
client.Update(e, media_source=mediasource)
def _run_edit(client, options, args): import subprocess from gdata.docs.data import MIMETYPES from gdata.data import MediaSource if not os.path.exists('/tmp/googlecl'): os.mkdir('/tmp/googlecl') entries = client.get_doclist(options.title) if len(entries) > 1: print 'More than one match, only editing the first result.'...
path = path.rstrip('/')
path = path.rstrip(os.path.sep)
def upload_docs(self, paths, title=None, folder_entry=None, file_ext=None, **kwargs): """Upload a list of documents or directories.
(email, password) = read_creds(cred_path) options.user = email
if os.path.exists(cred_path): (email, password) = read_creds(cred_path) options.user = email
def run_once(options, args): """Run one command. Keyword arguments: options: The options class as built and returned by optparse. args: The arguments to google-cl, also as returned by optparse. """ if len(args) < 2: print 'Must specify at least a service and a task!' return service = args[0] if not is_supported_servi...
test_uri = gdata.docs.service.DocumentQuery().ToUri() return googlecl.service.BaseServiceCL.IsTokenValid(self, test_uri)
docs_uri = gdata.docs.service.DocumentQuery().ToUri() sheets_uri = \ 'https://spreadsheets.google.com/feeds/spreadsheets/private/full' docs_test = googlecl.service.BaseServiceCL.IsTokenValid(self, docs_uri) sheets_test = googlecl.service.BaseServiceCL.IsTokenValid(self, sheets_uri) return docs_test and sheets_test
def is_token_valid(self, test_uri=None): """Check that the token being used is valid.""" if not test_uri: test_uri = gdata.docs.service.DocumentQuery().ToUri() return googlecl.service.BaseServiceCL.IsTokenValid(self, test_uri)
print 'Removing spreadsheets from list of documents...' print '(Downloading spreadsheets through the API is currently broken, sorry).' entries = [e for e in entries if get_document_type(e) != SPREADSHEET_LABEL]
def _run_get(client, options, args): if not hasattr(client, 'Export'): print 'Downloading documents is not supported for gdata-python-client < 2.0' return if not args: path = os.getcwd() else: path = args[0] if not os.path.exists(path): print 'Path ' + path + ' does not exist!' return folder_entries = client.get_folder...
if doc_type == SPREADSHEET_LABEL: print 'Sorry, cannot edit or download spreadsheets.'
format_ext = options.format or get_extension(doc_type) editor = options.editor or get_editor(doc_type) if not editor: print 'No editor defined!' print 'Define an "editor" option in your config file, set the ' +\ 'EDITOR environment variable, or pass an editor in with --editor.'
def _run_edit(client, options, args): if not hasattr(client, 'Export'): print 'Editing documents is not supported' +\ ' for gdata-python-client < 2.0' return folder_entry_list = client.get_folder(options.folder) doc_entry = client.get_single_doc(options.title, folder_entry_list) if not doc_entry: print 'No matching doc...
else: format_ext = options.format or get_extension(doc_type) editor = options.editor or get_editor(doc_type) if not editor: print 'No editor defined!' print 'Define an "editor" option in your config file, set the ' +\ 'EDITOR environment variable, or pass an editor in with --editor.' return client.edit_doc(doc_entry, e...
client.edit_doc(doc_entry, editor, format_ext)
def _run_edit(client, options, args): if not hasattr(client, 'Export'): print 'Editing documents is not supported' +\ ' for gdata-python-client < 2.0' return folder_entry_list = client.get_folder(options.folder) doc_entry = client.get_single_doc(options.title, folder_entry_list) if not doc_entry: print 'No matching doc...
do_globbing(command_string.strip(), final_args_list)
do_globbing(command_string.strip().split(), final_args_list)
def do_globbing(args, final_args_list): """Do filename expansion. Uses glob.glob to expand the default special characters of bash. Note that the command line will leave in arguments that do not expand to anything, unlike glob.glob. For example, entering 'myprogram.py total_nonsense*.txt' will pass through 'total_nonse...
albums = self.GetAlbum(title=title)
albums = self.GetAlbum(title=title, regex=regex)
def DeleteAlbum(self, title, regex=False): """Delete album(s). Keyword arguments: title -- albums matching this title should be deleted. regex -- indicates if regular expressions should be used in the title. (Default False) """ albums = self.GetAlbum(title=title) if not albums: print 'No albums with title', title for...
delete = raw_input('Are you sure you want to delete album ' +
delete = raw_input('Are you SURE you want to delete album ' +
def DeleteAlbum(self, title, regex=False): """Delete album(s). Keyword arguments: title -- albums matching this title should be deleted. regex -- indicates if regular expressions should be used in the title. (Default False) """ albums = self.GetAlbum(title=title) if not albums: print 'No albums with title', title for...
'? (Y/n): ') if not delete or delete.lower() == 'y':
'? (y/N): ') if delete and delete.lower() == 'y':
def DeleteAlbum(self, title, regex=False): """Delete album(s). Keyword arguments: title -- albums matching this title should be deleted. regex -- indicates if regular expressions should be used in the title. (Default False) """ albums = self.GetAlbum(title=title) if not albums: print 'No albums with title', title for...
if (err.args[0]['status'] == 400 and err.args[0]['body'].find('convert') != -1): LOG.error(err) LOG.info('Is this a new-version document? gdata has a bug' + ' preventing updates on new version documents.' + ' Please follow the instructions on the wiki FAQ ' + ' to convert your document.') new_path = safe_move(path, '.'...
LOG.error(err) new_path = safe_move(path, '.') LOG.info('Moved edited document to ' + new_path)
def edit_doc(self, doc_entry_or_title, editor, file_format, folder_entry_or_path=None): """Edit a document. Keyword arguments: doc_entry_or_title: DocEntry of the existing document to edit, or title of the document to create. editor: Name of the editor to use. Should be executable from the user's working directory. fi...
try: self.CreateContact(contact_entry) except self.request_error, err: LOG.error(err)
if contact_entry: try: self.CreateContact(contact_entry) except self.request_error, err: LOG.error(err)
def add_contact_string(self, string_or_csv_file): """Add contact(s).
for entry in response_feed.entry: print 'batch id: %s' % (entry.batch_id.text,) print 'status: %s' % (entry.batch_status.code,) print 'reason: %s' % (entry.batch_status.reason,)
def _batch_delete_recur(self, date, event, cal_user): """Delete a subset of instances of recurring events.""" request_feed = gdata.calendar.CalendarEventFeed() single_events = self.get_events(cal_user, date=date, title=event.title.text, expand_recurrence=True) delete_events = [e for e in single_events if e.original_eve...
recurring_events = [e for e in events if e.recurrence]
recurring_events = [e for e in events if e.recurrence and e.when]
def delete_events(self, events, date, calendar_user): """Delete events from a calendar. Keyword arguments: events: List of non-expanded calendar events to delete. date: Date string specifying the date range of the events, as the date option. calendar_user: "User" of the calendar to delete events from. """ single_even...
if not end_date: end_date = 'the distant future' if not start_date: start_date = 'the dawn of time' prompt_str = ('1) Instances between %s and %s\n' + '2) All events in this series\n' + '3) All events following %s\n' + '4) Do not delete') % (start_date, end_date, end_date)
option_list = [('All events in this series', 'ALL')] if start_date and end_date: option_list.append(('Instances between ' + start_date + ' and ' + end_date, date)) elif start_date or end_date: delete_date = (start_date or end_date) option_list.append(('Instances on ' + delete_date, _tomorrowize(delete_date))) option_li...
def delete_events(self, events, date, calendar_user): """Delete events from a calendar. Keyword arguments: events: List of non-expanded calendar events to delete. date: Date string specifying the date range of the events, as the date option. calendar_user: "User" of the calendar to delete events from. """ single_even...
delete_selection = 0 while delete_selection < 1 or delete_selection > 4: delete_selection = int(raw_input('Delete "%s"?\n%s\n' %
delete_selection = -1 while delete_selection < 0 or delete_selection > len(option_list)-1: delete_selection = int(raw_input('Delete "%s"?\n%s' %
def delete_events(self, events, date, calendar_user): """Delete events from a calendar. Keyword arguments: events: List of non-expanded calendar events to delete. date: Date string specifying the date range of the events, as the date option. calendar_user: "User" of the calendar to delete events from. """ single_even...
if delete_selection == 1: self._batch_delete_recur(date, event, calendar_user) elif delete_selection == 2:
option = option_list[delete_selection] if option[1] == 'ALL':
def delete_events(self, events, date, calendar_user): """Delete events from a calendar. Keyword arguments: events: List of non-expanded calendar events to delete. date: Date string specifying the date range of the events, as the date option. calendar_user: "User" of the calendar to delete events from. """ single_even...
elif delete_selection == 3: self._batch_delete_recur(start_date, event, calendar_user)
elif option[1] != 'NONE': try: self._batch_delete_recur(option[1], event, calendar_user) except EventsNotFound: print 'No events found matching request!'
def delete_events(self, events, date, calendar_user): """Delete events from a calendar. Keyword arguments: events: List of non-expanded calendar events to delete. date: Date string specifying the date range of the events, as the date option. calendar_user: "User" of the calendar to delete events from. """ single_even...
now = datetime.datetime.now() tomorrow = now + datetime.timedelta(days=1) options.date = now.strftime(util.DATE_FORMAT) + ',' + \ tomorrow.strftime(util.DATE_FORMAT)
options.date = _tomorrowize()
def _run_list_today(client, options, args): now = datetime.datetime.now() tomorrow = now + datetime.timedelta(days=1) options.date = now.strftime(util.DATE_FORMAT) + ',' + \ tomorrow.strftime(util.DATE_FORMAT) _run_list(client, options, args)
client.delete_events(events, options.date, cal_user)
try: client.delete_events(events, options.date, cal_user) except EventsNotFound: print 'No events found that match your options!'
def _run_delete(client, options, args): cal_user = client.get_calendar_user(options.cal) if not cal_user: print 'No calendar matches "' + options.cal + '"' return events = client.get_events(cal_user, date=options.date, title=options.title, query=options.query, expand_recurrence=False) client.delete_events(events, optio...
def do_globbing(args, final_args_list): """Do filename expansion. Uses glob.glob to expand the default special characters of bash. Note that the command line will leave in arguments that do not expand to anything, unlike glob.glob. For example, entering 'myprogram.py total_nonsense*.txt' will pass through 'total_nonse...
def do_globbing(args, final_args_list): """Do filename expansion.
quote_index = command_string.find('"') if quote_index == -1: args_list = command_string.split() final_args_list = [] do_globbing(args_list, final_args_list) else: final_args_list = [] while quote_index != -1: start = quote_index end = command_string.find('"', start+1) quoted_arg = command_string[start+1:end] non_quoted...
token_list = command_string.split() args_list = [] while token_list: tmp = token_list.pop(0) start_of_quote = tmp[0] == '"' end_quote = lambda s: s[-1] == '"' and len(s) > 1 and s[-2] != '\\' while start_of_quote and not end_quote(tmp): if token_list: tmp += ' ' + token_list.pop(0)
def do_globbing(args, final_args_list): """Do filename expansion.
quote_index = -1 if command_string: do_globbing(command_string.strip().split(), final_args_list) return final_args_list
raise Error('Encountered end of string without finding matching "') if start_of_quote: args_list.append(tmp[1:-1]) else: while tmp[-1] == '\\' and len(tmp) > 1 and tmp[-2] != '\\': if token_list: tmp = tmp[:-1] + ' ' + token_list.pop(0) else: raise Error('Encountered end of string ending in \\') expanded_args = glob...
def do_globbing(args, final_args_list): """Do filename expansion.
args_list = expand_as_command_line(command_string)
try: args_list = expand_as_command_line(command_string) except Error, err: LOG.error(err) continue
def run_interactive(parser): """Run an interactive shell for the google commands. Keyword arguments: parser: Object capable of parsing a list of arguments via parse_args. """ history_file = googlecl.get_data_path(googlecl.HISTORY_FILENAME) try: import readline try: readline.read_history_file(history_file) except IOEr...
options.src = expand_as_command_line(options.src)
expanded_args = glob.glob(options.src) if expanded_args: options.src = expanded_args else: options.src = [options.src]
def run_once(options, args): """Run one command. Keyword arguments: options: Options instance as built and returned by optparse. args: Arguments to GoogleCL, also as returned by optparse. """ try: service = args.pop(0) task_name = args.pop(0) except IndexError: if service == 'help': print_help() else: LOG.error('Must...
LOG.info('Backup or delete ' + token_path + ' and try again') return False
failed_file = True
def remove_access_token(service, user): """Remove an auth token for a particular user and service.""" import pickle token_path = get_data_path(TOKENS_FILENAME_FORMAT % user) success = False if os.path.exists(token_path): with open(token_path, 'r+') as token_file: try: token_dict = pickle.load(token_file) except ImportE...
pickle.dump(token_dict, token_file) success = True
try: pickle.dump(token_dict, token_file) except IOError, err: LOG.error(err) if err.errno == 0: file_invalid = True else: success = True if file_invalid: _move_failed_token_file(token_path)
def remove_access_token(service, user): """Remove an auth token for a particular user and service.""" import pickle token_path = get_data_path(TOKENS_FILENAME_FORMAT % user) success = False if os.path.exists(token_path): with open(token_path, 'r+') as token_file: try: token_dict = pickle.load(token_file) except ImportE...
new_path = token_path + '.failed' os.rename(token_path, new_path) print 'Moved ' + token_path + ' to ' + new_path
_move_failed_token_file(token_path)
def write_access_token(service, user, token): """Write an authorization token to a file. Keyword arguments: service: Service the token is for. E.g. 'picasa', 'docs', 'blogger'. user: Username / email the token is associated with. """ import pickle import stat token_path = get_data_path(TOKENS_FILENAME_FORMAT % user, ...
with open(token_path, 'r') as token_file:
with open(token_path, 'rb') as token_file:
def read_access_token(service, user): """Try to read an authorization token from a file. Keyword arguments: service: Service the token is for. E.g. 'picasa', 'docs', 'blogger'. user: Username / email the token is associated with. Returns: The access token, if it exists. If there is no access token, return NoneType. ...
with open(token_path, 'r') as token_file: token_dict = pickle.load(token_file)
with open(token_path, 'rb') as token_file: try: token_dict = pickle.load(token_file) except (KeyError, IndexError): print 'Failed to load token_file (may be corrupted?)' file_invalid = True else: file_invalid = False if file_invalid: new_path = token_path + '.failed' os.rename(token_path, new_path) print 'Moved ' + tok...
def write_access_token(service, user, token): """Write an authorization token to a file. Keyword arguments: service: Service the token is for. E.g. 'picasa', 'docs', 'blogger'. user: Username / email the token is associated with. """ import pickle import stat token_path = os.path.join(GOOGLE_CL_DIR, TOKENS_FILENAME_F...
with open(token_path, 'w') as token_file:
with open(token_path, 'wb') as token_file:
def write_access_token(service, user, token): """Write an authorization token to a file. Keyword arguments: service: Service the token is for. E.g. 'picasa', 'docs', 'blogger'. user: Username / email the token is associated with. """ import pickle import stat token_path = os.path.join(GOOGLE_CL_DIR, TOKENS_FILENAME_F...
if path:
if not path: path = get_config_path(create_missing_dir=True) if not path: LOG.error('Could not create config directory!') return False if not os.path.exists(path): print 'Did not find config / preferences file at ' + path print '... making new one.' else:
def set_options(): """Set the most basic options in the config file.""" import googlecl import getpass import socket # These may be useful to define at the module level, but for now, # keep them here. # REMEMBER: updating these means you need to update the CONFIG readme. default_hostid = getpass.getuser() + '@' + sock...
print err
LOG.error(err)
def set_options(): """Set the most basic options in the config file.""" import googlecl import getpass import socket # These may be useful to define at the module level, but for now, # keep them here. # REMEMBER: updating these means you need to update the CONFIG readme. default_hostid = getpass.getuser() + '@' + sock...
else: if not os.path.exists(GOOGLE_CL_DIR): os.makedirs(GOOGLE_CL_DIR) config_path = os.path.join(GOOGLE_CL_DIR, CONFIG_FILENAME) if os.path.exists(config_path): CONFIG.read(config_path) else: print 'Did not find config / preferences file at ' + config_path print '... making new one.'
def set_options(): """Set the most basic options in the config file.""" import googlecl import getpass import socket # These may be useful to define at the module level, but for now, # keep them here. # REMEMBER: updating these means you need to update the CONFIG readme. default_hostid = getpass.getuser() + '@' + sock...
with open(config_path, 'w') as config_file:
with open(path, 'w') as config_file:
def set_options(): """Set the most basic options in the config file.""" import googlecl import getpass import socket # These may be useful to define at the module level, but for now, # keep them here. # REMEMBER: updating these means you need to update the CONFIG readme. default_hostid = getpass.getuser() + '@' + sock...
token_path = os.path.join(GOOGLE_CL_DIR, TOKENS_FILENAME_FORMAT % user)
token_path = get_data_path(TOKENS_FILENAME_FORMAT % user)
def read_access_token(service, user): """Try to read an authorization token from a file. Keyword arguments: service: Service the token is for. E.g. 'picasa', 'docs', 'blogger'. user: Username / email the token is associated with. Returns: The access token, if it exists. If there is no access token, return NoneType. ...
key_path = os.path.join(GOOGLE_CL_DIR, DEVKEY_FILENAME)
key_path = get_data_path(DEVKEY_FILENAME)
def read_devkey(): """Return the cached YouTube developer's key.""" key_path = os.path.join(GOOGLE_CL_DIR, DEVKEY_FILENAME) devkey = None if os.path.exists(key_path): with open(key_path, 'r') as key_file: devkey = key_file.read().strip() return devkey
token_path = os.path.join(GOOGLE_CL_DIR, TOKENS_FILENAME_FORMAT % user)
token_path = get_data_path(TOKENS_FILENAME_FORMAT % user)
def remove_access_token(service, user): """Remove an auth token for a particular user and service.""" import pickle token_path = os.path.join(GOOGLE_CL_DIR, TOKENS_FILENAME_FORMAT % user) success = False if os.path.exists(token_path): with open(token_path, 'r+') as token_file: token_dict = pickle.load(token_file) try: ...
config_path = os.path.join(GOOGLE_CL_DIR, CONFIG_FILENAME)
config_path = get_config_path()
def set_missing_default(section, option, value, config_path=None): """Set the option for a section if not defined already. Keyword arguments: section: Title of the section to set the option in. option: Option to set. value: Value to give the option. config_path: Path to the configuration file. Default None to use the ...
token_path = os.path.join(GOOGLE_CL_DIR, TOKENS_FILENAME_FORMAT % user)
token_path = get_data_path(TOKENS_FILENAME_FORMAT % user, create_missing_dir=True)
def write_access_token(service, user, token): """Write an authorization token to a file. Keyword arguments: service: Service the token is for. E.g. 'picasa', 'docs', 'blogger'. user: Username / email the token is associated with. """ import pickle import stat token_path = os.path.join(GOOGLE_CL_DIR, TOKENS_FILENAME_F...
start_time_data = time.strptime(when.start_time[:-10],
start_time_data = time.strptime(when.start_time[:19],
def get_datetimes(cal_entry): """Get datetime objects for the start and end of the event specified by a calendar entry. Keyword arguments: cal_entry: A CalendarEventEntry. Returns: (start_time, end_time, freq) where start_time - datetime object of the start of the event. end_time - datetime object of the end of the e...
end_time_data = time.strptime(when.end_time[:-10],
end_time_data = time.strptime(when.end_time[:19],
def get_datetimes(cal_entry): """Get datetime objects for the start and end of the event specified by a calendar entry. Keyword arguments: cal_entry: A CalendarEventEntry. Returns: (start_time, end_time, freq) where start_time - datetime object of the start of the event. end_time - datetime object of the end of the e...
if self.logged_in: folder_feed = self.GetDocList(uri='/feeds/default/private/full/-/folder') self.folder_id = {} for f in folder_feed.entry: self.folder_id[f.title.text] = f.resource_id.text
def login(self, email, password): """Log in to the docs service. Keyword arguments: email: Email account to use. password: Password associated with said account. Returns: Nothing, but sets self.logged_in to true on success. """ self.logged_in = False if not (email and password): print ('You must give an email/passwo...
(Defaults to the names of the files). folder: Folder to put the files in. (Defaults to the root folder).
(Default None for the names of the files). folder: Folder to put the files in. (Default None for the root folder).
def upload_docs(self, paths, title=None, folder=None, convert=True): """Upload a document. Keyword arguments: paths: Paths of files to upload. title: Title to give the files once uploaded. (Defaults to the names of the files). folder: Folder to put the files in. (Defaults to the root folder). convert: If True, convert...
if folder and self.folder_id.has_key(folder): folder_id = self.folder_id[folder] uri = (gdata.docs.client.FOLDERS_FEED_TEMPLATE % urllib.quote_plus(folder_id)) else:
uri = '' if folder: folder_feed = self.GetDocList(uri='/feeds/default/private/full/-/folder') folder_entry = None for f in folder_feed.entry: if f.title.text == folder: folder_entry = f break if not folder_entry: create_folder = raw_input('Folder ' + folder + ' not found. Create it? (y/N): ') if create_folder.lower() =...
def upload_docs(self, paths, title=None, folder=None, convert=True): """Upload a document. Keyword arguments: paths: Paths of files to upload. title: Title to give the files once uploaded. (Defaults to the names of the files). folder: Folder to put the files in. (Defaults to the root folder). convert: If True, convert...
if on_homepath: if temp_arg_list: tmp = [] for sub_arg in temp_arg_list: tmp.append(os.path.expanduser(sub_arg)) temp_arg_list = tmp else: arg = os.path.expanduser(arg)
def expand_args(args, on_linesep, on_glob, on_homepath): """Expands arguments list. Args: on_linesep: Set True to split on occurrences of os.linesep. This is reasonably safe -- line separators appear to be escaped when given to Python on the command line. on_glob: Set True to glob expressions. May not be safe! For exa...
video_format = options.format,
video_format=options.format or 'mp4',
def _run_get(client, options, args): if not args: LOG.error('Must provide destination of album(s)!') return base_path = args[0] client.DownloadAlbum(base_path, user=options.owner or options.user, video_format = options.format, title=options.title)
optional=['title', 'query', 'owner', 'format'],
optional=['title', 'owner', 'format'],
def _run_tag(client, options, args): entries = client.build_entry_list(user=options.owner or options.user, query=options.query, title=options.title, force_photos=True) if entries: client.TagPhotos(entries, options.tags) else: LOG.error('No matches for the title and/or query you gave.')
subprocess.call([editor, path])
command_args = shlex.split(safe_encode(editor)) + [path] subprocess.call(command_args)
def edit_doc(self, doc_entry_or_title, editor, file_ext, folder_entry_or_path=None): """Edit a document.
content_type = MIMETYPES[filename.split('.')[1]]
content_type = MIMETYPES[filename.split('.')[1].upper()]
def upload_docs(self, paths, title=None, folder=None, convert=True): """Upload a document. Keyword arguments: paths: Paths of files to upload. title: Title to give the files once uploaded. (Defaults to the names of the files). folder: Folder to put the files in. (Defaults to the root folder). convert: If True, convert...
DOCUMENTS_NAMESPACE = 'http://schemas.google.com/docs/2007'
def __str__(self): if len(self.args) == 1: return 'Unexpected extension: ' + self.args[0] else: return str(self.args)
def get_doclist(self, title=None, folder_name=None):
def get_doclist(self, title=None, folder_entry_list=None):
def get_doclist(self, title=None, folder_name=None): """Get a list of document entries from a feed. Keyword arguments: title: String to use when looking for entries to return. Will be compared to entry.title.text, using regular expressions if self.use_regex. (Default None for all entries from feed). folder_name: Strin...
(Default None for all entries from feed). folder_name: String to match against folder titles. Only files found in folders with matching titles will be returned. (Default None for all folders).
Default None for all entries from feed. folder_entry_list: List of GDataEntry's of folders to get from. Only files found in these folders will be returned. Default None for all folders.
def get_doclist(self, title=None, folder_name=None): """Get a list of document entries from a feed. Keyword arguments: title: String to use when looking for entries to return. Will be compared to entry.title.text, using regular expressions if self.use_regex. (Default None for all entries from feed). folder_name: Strin...
if folder_name: query = gdata.docs.service.DocumentQuery(categories=['folder'], params={'showfolders': 'true'}) feed = self.Query(query.ToUri())
if folder_entry_list:
def get_doclist(self, title=None, folder_name=None): """Get a list of document entries from a feed. Keyword arguments: title: String to use when looking for entries to return. Will be compared to entry.title.text, using regular expressions if self.use_regex. (Default None for all entries from feed). folder_name: Strin...
for folder in feed.entry: if ((self.use_regex and re.match(folder_name, folder.title.text)) or (not self.use_regex and folder_name == folder.title.text)): contents = self.QueryDocumentListFeed(uri=folder.content.src) if not title: entries.extend(contents.entry) elif self.use_regex: entries.extend([entry for entry in c...
for folder in folder_entry_list: entries.extend(self.GetEntries(folder.content.src, title, converter=gdata.docs.DocumentListFeedFromString))
def get_doclist(self, title=None, folder_name=None): """Get a list of document entries from a feed. Keyword arguments: title: String to use when looking for entries to return. Will be compared to entry.title.text, using regular expressions if self.use_regex. (Default None for all entries from feed). folder_name: Strin...
def get_single_doc(self, title=None, folder=None): """Return exactly one file. Uses GetEntries to retrieve the entries, then asks the user to select one of them by entering a number.
def get_single_doc(self, title=None, folder_entry_list=None): """Return exactly one doc_entry.
def get_single_doc(self, title=None, folder=None): """Return exactly one file. Uses GetEntries to retrieve the entries, then asks the user to select one of them by entering a number. Keyword arguments: title: Title to match on. See get_doclist. (Default None). folder: Folders to look in. See get_doclist. (Default Non...
title: Title to match on. See get_doclist. (Default None). folder: Folders to look in. See get_doclist. (Default None).
title: Title to match on for document. Default None for any title. folder_entry_list: GDataEntry of folders to look in. Default None for any folder.
def get_single_doc(self, title=None, folder=None): """Return exactly one file. Uses GetEntries to retrieve the entries, then asks the user to select one of them by entering a number. Keyword arguments: title: Title to match on. See get_doclist. (Default None). folder: Folders to look in. See get_doclist. (Default Non...
entries = self.get_doclist(title, folder) if not entries:
if folder_entry_list: if len(folder_entry_list) == 1: return self.GetSingleEntry(folder_entry_list[0].content.src, title, converter=gdata.docs.DocumentListFeedFromString) else: entries = self.get_doclist(title, folder_entry_list) return self.GetSingleEntry(entries, title) else: return self.GetSingleEntry(gdata.docs.s...
def get_single_doc(self, title=None, folder=None): """Return exactly one file. Uses GetEntries to retrieve the entries, then asks the user to select one of them by entering a number. Keyword arguments: title: Title to match on. See get_doclist. (Default None). folder: Folders to look in. See get_doclist. (Default Non...
elif len(entries) == 1: return entries[0] elif len(entries) > 1: print 'More than one match for title ' + (title or '') for num, entry in enumerate(entries): print '%i) %s' % (num, entry.title.text) selection = -1 while selection < 0 or selection > len(entries)-1: selection = int(raw_input('Please select one of the ite...
GetFolder = get_folder
def get_single_doc(self, title=None, folder=None): """Return exactly one file. Uses GetEntries to retrieve the entries, then asks the user to select one of them by entering a number. Keyword arguments: title: Title to match on. See get_doclist. (Default None). folder: Folders to look in. See get_doclist. (Default Non...
def upload_docs(self, paths, title=None, folder=None, format=None):
def upload_docs(self, paths, title=None, folder_entry=None, file_format=None):
def upload_docs(self, paths, title=None, folder=None, format=None): """Upload a document. Keyword arguments: paths: Paths of files to upload. title: Title to give the files once uploaded. (Default None for the names of the files). folder: Folder to upload into. (Default None for no folder). format: Replace (or specify...
(Default None for the names of the files). folder: Folder to upload into. (Default None for no folder). format: Replace (or specify) the extension on the file when figuring
Default None for the names of the files. folder_entry: GDataEntry of the folder to upload into. Default None for no folder. file_format: Replace (or specify) the extension on the file when figuring
def upload_docs(self, paths, title=None, folder=None, format=None): """Upload a document. Keyword arguments: paths: Paths of files to upload. title: Title to give the files once uploaded. (Default None for the names of the files). folder: Folder to upload into. (Default None for no folder). format: Replace (or specify...
folder_entry = None if folder: if hasattr(self, 'Upload'): query = gdata.docs.service.DocumentQuery(categories=['folder'], params={'showfolders': 'true'}) folder_entry = self.GetSingleEntry(query.ToUri(), title=folder) else: print 'Uploading to folders not supported for gdata-python-client < 2.0' folder_entry = None
if folder_entry: post_uri = folder_entry.content.src else: post_uri = '/feeds/documents/private/full'
def upload_docs(self, paths, title=None, folder=None, format=None): """Upload a document. Keyword arguments: paths: Paths of files to upload. title: Title to give the files once uploaded. (Default None for the names of the files). folder: Folder to upload into. (Default None for no folder). format: Replace (or specify...
if format: extension = format
if file_format: extension = file_format
def upload_docs(self, paths, title=None, folder=None, format=None): """Upload a document. Keyword arguments: paths: Paths of files to upload. title: Title to give the files once uploaded. (Default None for the names of the files). folder: Folder to upload into. (Default None for no folder). format: Replace (or specify...
try: media = gdata.MediaSource(file_path=path, content_type=content_type) except IOError, err: print err continue title = title or filename.split('.')[0] if hasattr(self, 'Upload'): if folder_entry: entry = self.Upload(media, title, folder_or_uri=folder_entry) else: entry = self.Upload(media, title) elif extension.lo...
media = gdata.MediaSource(file_path=path, content_type=content_type) except IOError, err: print err continue entry_title = title or filename.split('.')[0] entry = gdata.docs.DocumentListEntry() entry.title = atom.Title(text=entry_title) if extension.lower() in ['csv', 'tsv', 'tab', 'ods', 'xls']: category = _make_ki...
def upload_docs(self, paths, title=None, folder=None, format=None): """Upload a document. Keyword arguments: paths: Paths of files to upload. title: Title to give the files once uploaded. (Default None for the names of the files). folder: Folder to upload into. (Default None for no folder). format: Replace (or specify...
print 'Upload success! Direct link: ' + entry.GetAlternateLink().href url_locs[filename] = entry.GetAlternateLink().href
print 'Upload success! Direct link: ' +\ new_entry.GetAlternateLink().href url_locs[filename] = new_entry.GetAlternateLink().href
def upload_docs(self, paths, title=None, folder=None, format=None): """Upload a document. Keyword arguments: paths: Paths of files to upload. title: Title to give the files once uploaded. (Default None for the names of the files). folder: Folder to upload into. (Default None for no folder). format: Replace (or specify...
entries = client.get_doclist(options.title, options.folder)
folder_entries = client.get_folder(options.folder) entries = client.get_doclist(options.title, folder_entries)
def _run_get(client, options, args): if not hasattr(client, 'Export'): print 'Downloading documents is not supported for gdata-python-client < 2.0' return if not args: path = os.getcwd() else: path = args[0] if not os.path.exists(path): print 'Path ' + path + ' does not exist!' return entries = client.get_doclist(optio...
entries = client.get_doclist(options.title, options.folder)
folder_entries = client.get_folder(options.folder) entries = client.get_doclist(options.title, folder_entries)
def _run_list(client, options, args): entries = client.get_doclist(options.title, options.folder) if args: style_list = args[0].split(',') else: style_list = googlecl.get_config_option(SECTION_HEADER, 'list_style').split(',') for entry in entries: print googlecl.service.entry_to_string(entry, style_list, delimiter=opti...
client.upload_docs(args, title=options.title, folder=options.folder, format=options.format)
folder_entries = client.get_folder(options.folder) folder_entry = client.get_single_entry(folder_entries) client.upload_docs(args, title=options.title, folder_entry=folder_entry, file_format=options.format)
def _run_upload(client, options, args): if not args: print 'Need to tell me what to upload!' return client.upload_docs(args, title=options.title, folder=options.folder, format=options.format)
doc_entry = client.get_single_doc(options.title, options.folder)
def _run_edit(client, options, args): doc_entry = client.get_single_doc(options.title, options.folder) if not hasattr(client, 'Export'): print 'Editing documents is not supported' +\ ' for gdata-python-client < 2.0' return if not doc_entry: print 'No matching documents found! Creating it.' new_entry = gdata.docs.Docume...
category = client._MakeKindCategory(DOCUMENT_LABEL)
category = _make_kind_category(DOCUMENT_LABEL)
def _run_edit(client, options, args): doc_entry = client.get_single_doc(options.title, options.folder) if not hasattr(client, 'Export'): print 'Editing documents is not supported' +\ ' for gdata-python-client < 2.0' return if not doc_entry: print 'No matching documents found! Creating it.' new_entry = gdata.docs.Docume...
doc_entry = client.Post(new_entry, '/feeds/documents/private/full')
folder_entries = client.get_folder(options.folder) folder_entry = client.get_single_entry(folder_entries) if folder_entry: post_uri = folder_entry.content.src else: post_uri = '/feeds/documents/private/full' doc_entry = client.Post(new_entry, post_uri)
def _run_edit(client, options, args): doc_entry = client.get_single_doc(options.title, options.folder) if not hasattr(client, 'Export'): print 'Editing documents is not supported' +\ ' for gdata-python-client < 2.0' return if not doc_entry: print 'No matching documents found! Creating it.' new_entry = gdata.docs.Docume...
optional=['format', 'editor']),
optional=['format', 'editor', 'folder']),
def _run_delete(client, options, args): entries = client.get_doclist(options.title) client.Delete(entries, 'document', googlecl.CONFIG.getboolean('GENERAL', 'delete_by_default'))
config.set_missing_default(section_header, 'user', client.email)
def run_once(options, args): """Run one command. Keyword arguments: options: Options instance as built and returned by optparse. args: Arguments to GoogleCL, also as returned by optparse. """ try: service = args.pop(0) task_name = args.pop(0) except IndexError: if service == 'help': print_help() else: LOG.error('Must...
os.mkdir(default_dir, mode)
os.makedirs(default_dir, mode)
def _get_xdg_path(filename, data_type, default_directories=None, create_missing_dir=False): """Get the full path to a file using XDG file layout spec. Follows XDG Base Directory Specification. (http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html). Tries default_directories and DEFAULT_GOOGLECL_DIR i...
with open(token_path, 'wb') as token_file: os.chmod(token_path, stat.S_IRUSR | stat.S_IWUSR) pickle.dump(token_dict, token_file)
if token_path: with open(token_path, 'wb') as token_file: os.chmod(token_path, stat.S_IRUSR | stat.S_IWUSR) pickle.dump(token_dict, token_file) else: LOG.debug('Cannot save access token!')
def write_access_token(service, user, token): """Write an authorization token to a file. Keyword arguments: service: Service the token is for. E.g. 'picasa', 'docs', 'blogger'. user: Username / email the token is associated with. """ import pickle import stat token_path = get_data_path(TOKENS_FILENAME_FORMAT % user, ...
def __init__(self, description, callback=None, required=None, optional=None,
def __init__(self, description, callback=None, required=[], optional=[],
def __init__(self, description, callback=None, required=None, optional=None, login_required=True, args_desc=''): """Constructor. Keyword arguments: description: Description of what the task does. callback: Function to use to execute task. (Default None, prints a message instead of running) required: Required options f...