new things
This commit is contained in:
parent
81e761c403
commit
1cec879add
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,5 @@ build/
|
||||
*.pyc
|
||||
*~
|
||||
venv/
|
||||
testing/
|
||||
padinfo.json
|
||||
|
31
etherdump/commands/join.py
Normal file
31
etherdump/commands/join.py
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from argparse import ArgumentParser
|
||||
import json, os, re
|
||||
from urllib import urlencode
|
||||
from urllib2 import urlopen, HTTPError, URLError
|
||||
|
||||
def group (items, key=lambda x: x):
|
||||
ret = []
|
||||
keys = {}
|
||||
for item in items:
|
||||
k = key(item)
|
||||
if k not in keys:
|
||||
keys[k] = []
|
||||
keys[k].append(item)
|
||||
for k in sorted(keys):
|
||||
keys[k].sort()
|
||||
ret.append(keys[k])
|
||||
return ret
|
||||
|
||||
def main(args):
|
||||
p = ArgumentParser("")
|
||||
p.add_argument("input", nargs="+", help="filenames")
|
||||
args = p.parse_args(args)
|
||||
|
||||
inputs = args.input
|
||||
inputs.sort()
|
||||
def base (x):
|
||||
return re.sub(r"(\.html)|(\.diff\.html)|(\.meta\.json)|(\.txt)$", "", x)
|
||||
from pprint import pprint
|
||||
pprint(group(inputs, base))
|
112
etherdump/commands/status.py
Normal file
112
etherdump/commands/status.py
Normal file
@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
from argparse import ArgumentParser
|
||||
import sys, json, re, os
|
||||
from datetime import datetime
|
||||
from urllib import urlencode
|
||||
from urllib2 import urlopen, HTTPError, URLError
|
||||
from math import ceil, floor
|
||||
from common import *
|
||||
|
||||
"""
|
||||
status (meta):
|
||||
Update meta data files for those that have changed.
|
||||
Check for changed pads by looking at revisions & comparing to existing
|
||||
|
||||
|
||||
design decisions...
|
||||
ok based on the fact that only the txt file is pushable (via setText)
|
||||
it makes sense to give this file "primacy" ... ie to put the other forms
|
||||
(html, diff.html) in a special place (if created at all). Otherwise this
|
||||
complicates the "syncing" idea....
|
||||
|
||||
"""
|
||||
|
||||
class PadItemException (Exception):
|
||||
pass
|
||||
|
||||
class PadItem ():
|
||||
def __init__ (self, padid=None, path=None, padexists=False):
|
||||
self.padexists = padexists
|
||||
if padid and path:
|
||||
raise PadItemException("only give padid or path")
|
||||
if not (padid or path):
|
||||
raise PadItemException("either padid or path must be specified")
|
||||
if padid:
|
||||
self.padid = padid
|
||||
self.path = padpath(padid, group_path="g")
|
||||
else:
|
||||
self.path = path
|
||||
self.padid = padpath2id(path)
|
||||
|
||||
@property
|
||||
def status (self):
|
||||
if self.fileexists:
|
||||
if self.padexists:
|
||||
return "S"
|
||||
else:
|
||||
return "F"
|
||||
elif self.padexists:
|
||||
return "P"
|
||||
else:
|
||||
return "?"
|
||||
|
||||
@property
|
||||
def fileexists (self):
|
||||
return os.path.exists(self.path)
|
||||
|
||||
def ignore_p (path, settings=None):
|
||||
if path.startswith("."):
|
||||
return True
|
||||
|
||||
def main (args):
|
||||
p = ArgumentParser("Check for pads that have changed since last sync (according to .meta.json)")
|
||||
# p.add_argument("padid", nargs="*", default=[])
|
||||
p.add_argument("--padinfo", default=".etherdump/settings.json", help="settings, default: .etherdump/settings.json")
|
||||
p.add_argument("--zerorevs", default=False, action="store_true", help="include pads with zero revisions, default: False (i.e. pads with no revisions are skipped)")
|
||||
p.add_argument("--pub", default=".", help="folder to store files for public pads, default: pub")
|
||||
p.add_argument("--group", default="g", help="folder to store files for group pads, default: g")
|
||||
p.add_argument("--skip", default=None, type=int, help="skip this many items, default: None")
|
||||
p.add_argument("--meta", default=False, action="store_true", help="download meta to PADID.meta.json, default: False")
|
||||
p.add_argument("--text", default=False, action="store_true", help="download text to PADID.txt, default: False")
|
||||
p.add_argument("--html", default=False, action="store_true", help="download html to PADID.html, default: False")
|
||||
p.add_argument("--dhtml", default=False, action="store_true", help="download dhtml to PADID.dhtml, default: False")
|
||||
p.add_argument("--all", default=False, action="store_true", help="download all files (meta, text, html, dhtml), default: False")
|
||||
args = p.parse_args(args)
|
||||
|
||||
info = loadpadinfo(args.padinfo)
|
||||
data = {}
|
||||
data['apikey'] = info['apikey']
|
||||
|
||||
padsbypath = {}
|
||||
|
||||
# listAllPads
|
||||
padids = getjson(info['apiurl']+'listAllPads?'+urlencode(data))['data']['padIDs']
|
||||
padids.sort()
|
||||
for padid in padids:
|
||||
pad = PadItem(padid=padid, padexists=True)
|
||||
padsbypath[pad.path] = pad
|
||||
|
||||
files = os.listdir(args.pub)
|
||||
files = [x for x in files if not ignore_p(x)]
|
||||
files.sort()
|
||||
for p in files:
|
||||
pad = padsbypath.get(p)
|
||||
if not pad:
|
||||
pad = PadItem(path=p)
|
||||
padsbypath[pad.path] = pad
|
||||
|
||||
pads = padsbypath.values()
|
||||
pads.sort(key=lambda x: (x.status, x.padid))
|
||||
|
||||
curstat = None
|
||||
for p in pads:
|
||||
if p.status != curstat:
|
||||
curstat = p.status
|
||||
if curstat == "F":
|
||||
print ("New/changed files")
|
||||
elif curstat == "P":
|
||||
print ("New/changed pads")
|
||||
elif curstat == ".":
|
||||
print ("Up to date")
|
||||
print (" ", p.status, p.padid)
|
Loading…
Reference in New Issue
Block a user