Skip to content
This repository was archived by the owner on Jul 24, 2021. It is now read-only.

I made it work on windows 7 and support Chinese #3

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/README.txt
*.pyc
*.pyo
.idea
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
python-skydrive
----------------------------------------
I forked it from [mk-fg](https://github.com/mk-fg/python-skydrive). Big thanks to mk-fg. This is what I did:
* Make it work well on both windows 7 and ubuntu 12.10. Never test it on other os.
* Support Chinese.

Schedule(Command-line)
----------------------------------------
operations windows 7 ubuntu Remark
auth √ √
quota √ √
recent √ √
info √ √
info_set √ √ /python/你好/p.py {\"name\":\"你好.py\"}
link √ √
ls √ √
mkdir √ √
get √ √
put √ √
cp √ √
mv √ √
rm √ √
comments √ √
comment_add √ √
comment_delete √ √ comment.262611c013bb05f6.262611C013BB05F6\!1837.262611C013BB05F6\!1842
tree √ √


python-skydrive
----------------------------------------
Python and command-line interface for [SkyDrive API (version
5.0)](http://msdn.microsoft.com/en-us/library/live/hh826521).

Expand Down Expand Up @@ -57,7 +84,8 @@ Then just type whatever commands you want to (and don't forget `skydrive-cli
image1.jpg: photo
image2.jpg: photo

% skydrive-cli get Pics/image1.jpg > downloaded_image1.jpg
% skydrive-cli get Pics/image1.jpg > downloaded_image1.jpg # linux only
% skydrive-cli get Pics/image1.jpg downloaded_image1.jpg # linux && windows
% skydrive-cli put downloaded_image1.jpg
% skydrive-cli ls

Expand Down Expand Up @@ -182,9 +210,14 @@ without any installation, if that's the only thing you need there.
(I strongly recommend using version 0.14.0 or higher - ideally 1.0.0+, see
"Known Issues" section below for rationale)

* (optional, recommended, windows 7 necessary) [win32all](http://sourceforge.net/projects/pywin32/)

* (optional, recommended) [PyYAML](http://pyyaml.org) - required for CLI tool
and optional persistent-state ("conf") module only.

* (optional, recommended) [chardet](http://pypi.python.org/pypi/chardet) - used to detect the coding(like
gbk, utf-8 and so on) of the argument from cmd to support Chinese.


### Known Issues

Expand Down
14 changes: 7 additions & 7 deletions doc/api.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.. automodule:: skydrive.api_v5
:exclude-members: SkyDriveHTTPClient, SkyDriveAuth,
SkyDriveAPIWrapper, SkyDriveAPI, PersistentSkyDriveAPI
:exclude-members: SkyDriveHTTPClient, SkyDriveAuth,
SkyDriveAPIWrapper, SkyDriveAPI, PersistentSkyDriveAPI

.. autoclass:: SkyDriveHTTPClient
.. autoclass:: SkyDriveAuth
.. autoclass:: SkyDriveAPIWrapper
.. autoclass:: SkyDriveAPI
.. autoclass:: SkyDriveHTTPClient
.. autoclass:: SkyDriveAuth
.. autoclass:: SkyDriveAPIWrapper
.. autoclass:: SkyDriveAPI

.. autoclass:: PersistentSkyDriveAPI
:exclude-members: rx:^from_conf|conf_(path_default|update_keys)$
:exclude-members: rx:^from_conf|conf_(path_default|update_keys)$
:inherited-members:
1 change: 0 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
sys.path.insert(0, abspath('..')) # for module itself
sys.path.append(abspath('.')) # for extenstions


needs_sphinx = '1.1'
extensions = ['sphinx.ext.autodoc', 'sphinx_local_hooks']

Expand Down
104 changes: 57 additions & 47 deletions doc/sphinx_local_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,81 @@
from collections import Iterable
import os, sys, types, re


from sphinx.ext.autodoc import Documenter

_autodoc_add_line = Documenter.add_line


@ft.wraps(_autodoc_add_line)
def autodoc_add_line(self, line, *argz, **kwz):
tee = self.env.app.config.autodoc_dump_rst
if tee:
tee_line = self.indent + line
if isinstance(tee, file): tee.write(tee_line + '\n')
elif tee is True: print(tee_line)
else:
raise ValueError( 'Unrecognized'
' value for "autodoc_dump_rst" option: {!r}'.format(tee) )
return _autodoc_add_line(self, line, *argz, **kwz)
tee = self.env.app.config.autodoc_dump_rst
if tee:
tee_line = self.indent + line
if isinstance(tee, file):
tee.write(tee_line + '\n')
elif tee is True:
print(tee_line)
else:
raise ValueError('Unrecognized'
' value for "autodoc_dump_rst" option: {!r}'.format(tee))
return _autodoc_add_line(self, line, *argz, **kwz)


Documenter.add_line = autodoc_add_line


def process_docstring(app, what, name, obj, options, lines):
if not lines: return
if not lines: return

i, ld = 0, dict(enumerate(lines)) # to allow arbitrary peeks
i_max = max(ld)
i, ld = 0, dict(enumerate(lines)) # to allow arbitrary peeks
i_max = max(ld)

def process_line(i):
line, i_next = ld[i], i + 1
while i_next not in ld and i_next <= i_max: i_next += 1
line_next = ld.get(i_next)
def process_line(i):
line, i_next = ld[i], i + 1
while i_next not in ld and i_next <= i_max: i_next += 1
line_next = ld.get(i_next)

if line_next and line_next[0] in u' \t': # tabbed continuation of the sentence
ld[i] = u'{} {}'.format(line, line_next.strip())
del ld[i_next]
process_line(i)
elif line.endswith(u'.') or (line_next and line_next[0].isupper()): ld[i+0.5] = u''
if line_next and line_next[0] in u' \t': # tabbed continuation of the sentence
ld[i] = u'{} {}'.format(line, line_next.strip())
del ld[i_next]
process_line(i)
elif line.endswith(u'.') or (line_next and line_next[0].isupper()):
ld[i + 0.5] = u''

for i in xrange(i_max + 1):
if i not in ld: continue # was removed
process_line(i)
for i in xrange(i_max + 1):
if i not in ld: continue # was removed
process_line(i)

# Overwrite the list items inplace, extending the list if necessary
for i, (k, line) in enumerate(sorted(ld.viewitems())):
try: lines[i] = line
except IndexError: lines.append(line)
# Overwrite the list items inplace, extending the list if necessary
for i, (k, line) in enumerate(sorted(ld.viewitems())):
try:
lines[i] = line
except IndexError:
lines.append(line)


def skip_override(app, what, name, obj, skip, options):
if options.get('exclude-members'):
include_only = set( re.compile(k[3:])
for k in options['exclude-members'] if k.startswith('rx:') )
if include_only:
for pat in include_only:
if pat.search(name): break
else: return True
if what == 'exception':
return False if name == '__init__'\
and isinstance(obj, types.UnboundMethodType) else True
elif what == 'class':
if name in ['__init__', '__call__']\
and isinstance(obj, types.UnboundMethodType): return False
elif getattr(obj, 'im_class', None) is type: return False
return skip
if options.get('exclude-members'):
include_only = set(re.compile(k[3:])
for k in options['exclude-members'] if k.startswith('rx:'))
if include_only:
for pat in include_only:
if pat.search(name): break
else:
return True
if what == 'exception':
return False if name == '__init__' \
and isinstance(obj, types.UnboundMethodType) else True
elif what == 'class':
if name in ['__init__', '__call__'] \
and isinstance(obj, types.UnboundMethodType):
return False
elif getattr(obj, 'im_class', None) is type:
return False
return skip


def setup(app):
app.connect('autodoc-process-docstring', process_docstring)
app.connect('autodoc-skip-member', skip_override)
app.add_config_value('autodoc_dump_rst', None, True)
app.connect('autodoc-process-docstring', process_docstring)
app.connect('autodoc-skip-member', skip_override)
app.add_config_value('autodoc_dump_rst', None, True)
133 changes: 68 additions & 65 deletions doc/sphinx_text_to_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,74 @@ class FormatError(Exception): pass


def main():
import argparse
parser = argparse.ArgumentParser(
description='Convert sphinx-produced autodoc.apidoc text to markdown.')
parser.add_argument('src', nargs='?', help='Source file (default: use stdin).')
optz = parser.parse_args()

src = open(optz.src) if optz.src else sys.stdin
dst = sys.stdout

py_name = r'[\w_\d]+'
out = ft.partial(print, file=dst)

st_attrdoc = 0
st_cont, lse_nl = False, None

for line in src:
ls = line.strip()
if not ls: # blank line
out(line, end='')
continue

line_indent = re.search(r'^( +)', line)
if not line_indent: line_indent = 0
else:
line_indent = len(line_indent.group(1))
if line_indent % 3: raise FormatError('Weird indent size: {}'.format(line_indent))
line_indent = line_indent / 3

lp = line.split()
lse = re.sub(r'(<\S+) at 0x[\da-f]+(>)', r'\1\2', ls)
lse = re.sub(r'([_*<>])', r'\\\1', lse)
for url in re.findall(r'\b\w+://\S+', lse):
lse = lse.replace(url, url.replace(r'\_', '_'))
lse = re.sub(r'\bu([\'"])', r'\1', lse)
st_cont, lse_nl = bool(lse_nl), '' if re.search(r'\b\w+://\S+-$', lse) else '\n'

st_attrdoc_reset = True
if not line_indent:
if len(lp) > 2 and lp[0] == lp[1]:
if lp[0] in ('exception', 'class'): # class, exception
out('\n'*1, end='')
out('* **{}**'.format(' '.join(lse.split()[1:])))

else:
raise FormatError('Unhandled: {!r}'.format(line))

elif line_indent == 1:
if re.search(r'^(\w+ )?{}\('.format(py_name), ls): # function
out('\n'*1, end='')
out('{}* {}'.format(' '*4, lse))
st_attrdoc, st_attrdoc_reset = 8, False
elif re.search(r'^{}\s+=\s+'.format(py_name), ls): # attribute
out('{}* {}'.format(' '*4, lse))
st_attrdoc, st_attrdoc_reset = 8, False
elif lp[0] == 'Bases:': # class bases
out('{}{}'.format(' '*4, lse))
st_attrdoc, st_attrdoc_reset = 4, False
else: out('{}{}'.format(' '*(4 * st_cont), ls), end=lse_nl) # class docstring

else: # description line
if ls[0] in '-*': line = '\\' + line.lstrip()
out('{}{}'.format(' '*(st_attrdoc * st_cont), line.strip()), end=lse_nl)
st_attrdoc_reset = False

if st_attrdoc and st_attrdoc_reset: st_attrdoc = 0
import argparse

parser = argparse.ArgumentParser(
description='Convert sphinx-produced autodoc.apidoc text to markdown.')
parser.add_argument('src', nargs='?', help='Source file (default: use stdin).')
optz = parser.parse_args()

src = open(optz.src) if optz.src else sys.stdin
dst = sys.stdout

py_name = r'[\w_\d]+'
out = ft.partial(print, file=dst)

st_attrdoc = 0
st_cont, lse_nl = False, None

for line in src:
ls = line.strip()
if not ls: # blank line
out(line, end='')
continue

line_indent = re.search(r'^( +)', line)
if not line_indent:
line_indent = 0
else:
line_indent = len(line_indent.group(1))
if line_indent % 3: raise FormatError('Weird indent size: {}'.format(line_indent))
line_indent = line_indent / 3

lp = line.split()
lse = re.sub(r'(<\S+) at 0x[\da-f]+(>)', r'\1\2', ls)
lse = re.sub(r'([_*<>])', r'\\\1', lse)
for url in re.findall(r'\b\w+://\S+', lse):
lse = lse.replace(url, url.replace(r'\_', '_'))
lse = re.sub(r'\bu([\'"])', r'\1', lse)
st_cont, lse_nl = bool(lse_nl), '' if re.search(r'\b\w+://\S+-$', lse) else '\n'

st_attrdoc_reset = True
if not line_indent:
if len(lp) > 2 and lp[0] == lp[1]:
if lp[0] in ('exception', 'class'): # class, exception
out('\n' * 1, end='')
out('* **{}**'.format(' '.join(lse.split()[1:])))

else:
raise FormatError('Unhandled: {!r}'.format(line))

elif line_indent == 1:
if re.search(r'^(\w+ )?{}\('.format(py_name), ls): # function
out('\n' * 1, end='')
out('{}* {}'.format(' ' * 4, lse))
st_attrdoc, st_attrdoc_reset = 8, False
elif re.search(r'^{}\s+=\s+'.format(py_name), ls): # attribute
out('{}* {}'.format(' ' * 4, lse))
st_attrdoc, st_attrdoc_reset = 8, False
elif lp[0] == 'Bases:': # class bases
out('{}{}'.format(' ' * 4, lse))
st_attrdoc, st_attrdoc_reset = 4, False
else:
out('{}{}'.format(' ' * (4 * st_cont), ls), end=lse_nl) # class docstring

else: # description line
if ls[0] in '-*': line = '\\' + line.lstrip()
out('{}{}'.format(' ' * (st_attrdoc * st_cont), line.strip()), end=lse_nl)
st_attrdoc_reset = False

if st_attrdoc and st_attrdoc_reset: st_attrdoc = 0


if __name__ == '__main__': main()
Loading