def test_unicode_arg(self): from pbs import echo if IS_PY3: test = "漢字" else: test = "漢字".decode("utf8") p = echo(test).strip() self.assertEqual(test, p)
def test_change_default_encoding(self): import pbs self.assertEqual(pbs.config["DEFAULT_ENCODING"], "mbcs") pbs.set_default_encoding("utf8") ret = pbs.echo(u"נסיון") self.assertEqual(pbs.config["DEFAULT_ENCODING"], "utf8")
def makeTreeFromDir(backupname, paths): """ imports a path into the git repro and makes a tree from it. returns the tree sha """ clearIndex() topLevel = [] filesInTree = [] dirsInTree = [] emptyFileHash = None for path in paths: if not os.path.exists(path): fatal("Path '%s' does not exist, cannot backup" % path) bn = os.path.basename(path) if bn in topLevel: fatal( "Multiple paths ending in '%s' are being backed up, not supported" % bn) if os.path.isdir(path): # add current dir to the index (also import all objects) git('--work-tree', path, 'add', '-f', '.') # empty dirs are not added by the above, pretend there is a .gibkeep file in each # (we will delete this when extracting backups) for emptyDir in getEmptyDirs(path): if not emptyFileHash: emptyFileHash = git_pipe(pbs.echo('-n', ''), 'hash-object', '-w', '--stdin').strip() git('update-index', '--add', '--cacheinfo', '10644', emptyFileHash, os.path.join(os.path.relpath(emptyDir, path), '.gibkeep')) # write the tree for this and get the tree sha tree = git('write-tree').strip() clearIndex() dirsInTree.append((bn, tree)) else: fileHash = git('hash-object', '-w', path).strip() filesInTree.append((bn, fileHash)) clearIndex() # now make the final snapshot index for (dir, tree) in dirsInTree: git('read-tree', '-i', tree, '--prefix=%s/' % dir) for (file, hash) in filesInTree: # see http://git-scm.com/book/en/Git-Internals-Git-Objects # adding with 10644 means normal file (TODO perhaps check if it should be marked as executable) # cacheinfo means we have the hash, but no file in our work dir corresponding to it git('update-index', '--add', '--cacheinfo', '10644', hash, file) tree = git('write-tree').strip() clearIndex() return tree
def makeTreeFromDir(backupname,paths): """ imports a path into the git repro and makes a tree from it. returns the tree sha """ clearIndex() topLevel=[] filesInTree=[] dirsInTree=[] emptyFileHash=None for path in paths: if not os.path.exists(path): fatal("Path '%s' does not exist, cannot backup"%path) bn=os.path.basename(path) if bn in topLevel: fatal("Multiple paths ending in '%s' are being backed up, not supported"%bn) if os.path.isdir(path): # add current dir to the index (also import all objects) git('--work-tree',path,'add','-f','.') # empty dirs are not added by the above, pretend there is a .gibkeep file in each # (we will delete this when extracting backups) for emptyDir in getEmptyDirs(path): if not emptyFileHash: emptyFileHash=git_pipe(pbs.echo('-n',''),'hash-object','-w','--stdin').strip() git('update-index','--add','--cacheinfo','10644',emptyFileHash,os.path.join(os.path.relpath(emptyDir,path),'.gibkeep')) # write the tree for this and get the tree sha tree=git('write-tree').strip() clearIndex() dirsInTree.append((bn,tree)) else: fileHash=git('hash-object','-w',path).strip() filesInTree.append((bn,fileHash)) clearIndex() # now make the final snapshot index for (dir,tree) in dirsInTree: git('read-tree','-i',tree,'--prefix=%s/'%dir) for (file,hash) in filesInTree: # see http://git-scm.com/book/en/Git-Internals-Git-Objects # adding with 10644 means normal file (TODO perhaps check if it should be marked as executable) # cacheinfo means we have the hash, but no file in our work dir corresponding to it git('update-index','--add','--cacheinfo','10644',hash,file) tree=git('write-tree').strip() clearIndex() return tree
def test_long_option(self): from pbs import sed, echo out = sed(echo("test"), expression="s/test/lol/").strip() self.assertEqual(out, "lol")
def test_nt_internal_commands(self): from pbs import echo s1 = unicode(echo("test")).strip() s2 = 'test' self.assertEqual(s1, s2)
def test_bg_to_int(self): from pbs import echo # bugs with background might cause the following error: # ValueError: invalid literal for int() with base 10: '' self.assertEqual(int(echo("123", _bg=True)), 123)