Skip to content

Commit

Permalink
Little fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBachmann committed Feb 20, 2018
1 parent 5b864d1 commit e58b037
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ Some of these options can be defined on a per-repository basis already during of
### Configuration Commands ###
- `sos config set` sets a boolean flag, a string, or an initial list (semicolon-separated)
- `sos config unset` removes a boolean flag, a string, or an entire list
- `sos config add` adds a string entry to a list, and creates it if necessary
- `sos config rm` removes a string entry from a list. Must be typed exactly as the entry to remove
- `sos config add` adds one or more (semicolon-separated) string entry/entries to a list, and creates it if necessary
- `sos config rm` removes a string entry from a list. Must be typed exactly as the entry to remove. To remove the list, use `sos unset <key>`
- `sos config show` lists all defined configuration settings, including storage location/type (global, local, default)
- `sos config show <parameter>` show only one configuration item
- `sos config show flags|texts|lists` show supported settings per type
Expand Down
18 changes: 11 additions & 7 deletions sos/sos.coco
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Metadata:
using only parts of its attributes at any point in time. Use with care.
'''

singleton:configr.Configr? = None

def __init__(_, path:str? = None, offline:bool = False):
''' Create empty container object for various repository operations, and import configuration. '''
_.root:str = path ?? os.getcwd()
Expand All @@ -55,7 +57,9 @@ class Metadata:
_.paths:Dict[str,PathInfo] = {} # utf-8 encoded relative, normalized file system paths
_.commit:int? = None # current revision number

_.c:configr.Configr = configr.Configr(data = _.repoConf, defaults = loadConfig()) # load global configuration with defaults behind the local configuration
if Metadata.singleton is None: # only load once
Metadata.singleton = configr.Configr(data = _.repoConf, defaults = loadConfig()) # load global configuration with defaults behind the local configuration
_.c:configr.Configr = Metadata.singleton

def isTextType(_, filename:str) -> bool = ((mimetypes.guess_type(filename)[0] ?? "").startswith("text/") or any([fnmatch.fnmatch(filename, pattern) for pattern in _.c.texttype])) and not any([fnmatch.fnmatch(filename, pattern) for pattern in _.c.bintype])

Expand Down Expand Up @@ -204,7 +208,7 @@ class Metadata:
deps:List[Tuple[int,int]] = [(binfo.number, binfo.revision) for binfo in _.branches.values() if binfo.parent is not None and _.getParentBranch(binfo.number, 0) == branch] # get transitively depending branches
if deps: # need to copy all parent revisions to dependet branches first
minrev:int = min([e[1] for e in deps]) # minimum revision ever branched from parent (ignoring transitive branching!)
progress:indicator = ProgressIndicator()
progress:ProgressIndicator = ProgressIndicator()
for rev in range(0, minrev + 1): # rely on caching by copying revision-wise as long as needed in all depending branches
for dep, _rev in deps:
if rev <= _rev:
Expand Down Expand Up @@ -570,7 +574,7 @@ def commit(argument:str? = None, options:str[] = [], onlys:FrozenSet[str]? = Non
else: m.branches[m.branch] = dataCopy(BranchInfo, m.branches[m.branch], inSync = False) # track or simple mode: set branch dirty
if "--tag" in options and argument is not None: m.tags.append(argument); info("Version was tagged with %s" % argument) # memorize unique tag
m.saveBranches()
info(MARKER + "Created new revision r%02d%s (+%02d/-%02d/\u00b1%02d/*%02d)" % (revision, ((" '%s'" % argument) if argument is not None else ""), len(changes.additions), len(changes.deletions), len(changes.modifications), len(changes.moves)))
info(MARKER + "Created new revision r%02d%s (+%02d/-%02d/\u00b1%02d/*%02d)" % (revision, ((" '%s'" % argument) if argument is not None else ""), len(changes.additions) - len(changes.moves), len(changes.deletions) - len(changes.moves), len(changes.modifications), len(changes.moves)))

def status(argument:str? = None, vcs:str? = None, cmd:str? = None, options:str[] = [], onlys:FrozenSet[str]? = None, excps:FrozenSet[str]? = None):
''' Show branches and current repository state. '''
Expand Down Expand Up @@ -848,12 +852,12 @@ def log(options:str[] = []):
n.loadBranch(n.getParentBranch(m.branch, no))
commit = n.commits[no]
nxts:Dict[str,PathInfo] = next(changesetIterator)
news:FrozenSet[str] = frozenset(nxts.keys()) # side-effect: updates m.paths
_add:FrozenSet[str] = news - olds
news:FrozenSet[str] = frozenset(nxts.keys())
_add:FrozenSet[str] = news - olds # TODO determine moves
_del:FrozenSet[str] = olds - news
_mod:FrozenSet[str] = frozenset([_ for _, info in nxts.items() if _ in m.paths and m.paths[_].size != info.size and (m.paths[_].hash != info.hash if m.strict else m.paths[_].mtime != info.mtime)])
_txt:int = len([a for a in _add if m.isTextType(a)])
printo(" %s r%s @%s (+%02d/-%02d/*%02d +%02dT) |%s|%s" % ("*" if commit.number == maxi else " ", ("%%%ds" % nl) % commit.number, strftime(commit.ctime), len(_add), len(_del), len(_mod), _txt, (commit.message ?? ""), "TAG" if (commit.message ?? "") in m.tags else ""))
printo(" %s r%s @%s (+%02d/-%02d/\u00b1%02d/T%02d) |%s|%s" % ("*" if commit.number == maxi else " ", ("%%%ds" % nl) % commit.number, strftime(commit.ctime), len(_add), len(_del), len(_mod), _txt, (commit.message ?? ""), "TAG" if (commit.message ?? "") in m.tags else ""))
if '--changes' in options: m.listChanges(ChangeSet({a: None for a in _add}, {d: None for d in _del}, {m: None for m in _mod}, {})) # TODO moves detection?
if '--diff' in options: pass # _diff(m, changes) # needs from revision diff
olds = news
Expand All @@ -879,7 +883,7 @@ def dump(argument:str, options:str[] = []):
except Exception as E: Exit("Error creating backup copy before dumping. Please resolve and retry. %r" % E)
debug("Dumping revisions...")
if delta: warnings.filterwarnings('ignore', 'Duplicate name.*', UserWarning, "zipfile", 0) # don't show duplicate entries warnings
with zipfile.ZipFile(argument, "a", compression) as _zip: # create
with zipfile.ZipFile(argument, "a" if delta else "w", compression) as _zip: # create
_zip.debug = 0 # no debugging output
_zip.comment = ("Repository dump from %r" % strftime()).encode(UTF8)
repopath:str = os.path.join(os.getcwd(), metaFolder)
Expand Down
1 change: 1 addition & 0 deletions sos/tests.coco
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Tests(unittest.TestCase):
''' Entire test suite. '''

def setUp(_):
sos.Metadata.singleton = None
for entry in os.listdir(testFolder): # cannot remove testFolder on Windows when using TortoiseSVN as VCS
resource = os.path.join(testFolder, entry)
shutil.rmtree(resource) if os.path.isdir(resource) else os.unlink(resource)
Expand Down
2 changes: 1 addition & 1 deletion sos/utility.coco
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def relativize(root:str, filepath:str) -> Tuple[str,str] =
relpath = os.path.relpath(os.path.dirname(os.path.abspath(filepath)), root).replace(os.sep, SLASH)
relpath, os.path.join(relpath, os.path.basename(filepath)).replace(os.sep, SLASH)

def parseOnlyOptions(root:str, options:str[]) -> Tuple[FrozenSet[str]?, FrozenSet[str]?] =
def parseOnlyOptions(root:str, options:List[str]) -> Tuple[FrozenSet[str]?, FrozenSet[str]?] =
''' Returns set of --only arguments, and set or --except arguments. '''
cwd:str = os.getcwd()
onlys:List[str] = []; excps:List[str] = []; index:int = 0 # zero necessary as last start position
Expand Down

0 comments on commit e58b037

Please sign in to comment.