# mini_buildd.files module

mini_buildd.files.find(path, name)

  Find file name in path, recursively – return absolute path of first hit, else None

class mini_buildd.files.DebianName(package, version)

  Bases: `object`

  Debian package-related file names, based on package `name` (usually source name) and `version`

  Always strip epoch from version, and handles special mini-buildd types.

      >>> dfn = DebianName("mypkg", "7:1.2.3-1")
      >>> dfn.dsc()
      'mypkg_1.2.3-1.dsc'
      >>> dfn.changes("amd64")
      'mypkg_1.2.3-1_amd64.changes'
      >>> dfn.changes("mips")
      'mypkg_1.2.3-1_mips.changes'
      >>> dfn.changes("mips", apx="my-custom-apx")
      'mypkg_1.2.3-1_my-custom-apx_mips.changes'
      >>> dfn.buildlog("mips")
      'mypkg_1.2.3-1_mips.buildlog'

  classmethod uext(ext)
  gen(type_, apx=None, arch=None)
  dsc()
  changes(arch, apx=None)
  upload(arch, apx=None)
  buildlog(arch)
  json(apx, arch=None)

class mini_buildd.files.Tar

  Bases: `object`

  add(file_paths, arcdir='')
  save_as(file_path)
  classmethod extract(file_path, dest_path)

class mini_buildd.files.Path(base, subdirs=None, create=False)

  Bases: `object`

  PATH string with some convenience functionality

      >>> p = Path("/tmp", ["uff", None, "tata"])
      >>> p.base
      '/tmp'
      >>> p.sub
      'uff/tata'
      >>> p.full
      '/tmp/uff/tata'
      >>> p.join("more", "sub", "dirs")
      '/tmp/uff/tata/more/sub/dirs'

      >>> p = Path("/tmp")
      >>> p.sub
      ''

  create()
  new_sub(subdirs=None, create=False)
  join(*args)
  sub_join(*args)
  expire(older_than)

    Expire directories ‘older than’

  ifiles(path, extension, after=None, before=None)

    Fast recursive file finder using os.scandir()

  removeprefix(path)

class mini_buildd.files.File(name, description=None, snippet=None, comment='#', shebang=None, finalizer=None, placeholders=None)

  Bases: `deque`

  Line based text file (config or script)

      >>> pm = PerlModule("perl").add("# set foo\n$bar = undef;")
      >>> pm.get()
      '# set foo\n$bar = undef;\n1;\n'
      >>> pm.get(snippet=True)
      '# set foo\n$bar = undef;\n'
      >>> pm.get(snippet=True, comments=False)
      '$bar = undef;\n'

      >>> bs = BashScript("bash").add("# echo foo\necho bar")
      >>> bs.get()
      '#!/bin/bash -e\n# echo foo\necho bar\n'
      >>> bs.get(snippet=True)
      '# echo foo\necho bar\n'
      >>> bs.get(snippet=True, comments=False)
      'echo bar\n'

      >>> test_file = "/tmp/mini_buildd_test_conf_file"
      >>> if os.path.exists(test_file): os.remove(test_file)
      >>> File("test_file").add("my_option=7\n").update_as(test_file)
      True
      >>> File("test_file").add("my_option=7\n").update_as(test_file)
      False
      >>> File("test_file").add("my_option=8\n").update_as(test_file)
      True

      >>> dos = File("dos.txt").add_file("test-data/dos.txt")
      >>> with util.fopen("test-data/unix.txt", newline="") as unix: unix.read() == dos.get()
      True
      >>> with util.fopen("test-data/dos.txt", newline="") as dos_file: dos_file.read() == dos.get()
      False

  # rmtree: Enable with caution # >>> dir = Dir(“./test-data/dirtest”).add(File(“file1.txt”, snippet=”test1 data”)).add(File(“file2.txt”, snippet=”test2 data”)) # >>> import shutil # >>> shutil.rmtree(dir.path, ignore_errors=True) # >>> dir.update() # True # >>> dir.update() # False # >>> dir.update() # False # >>> dummy = dir[“file1.txt”].add(“nonne zeile”) # >>> dir.update() # True # >>> shutil.rmtree(dir.path)

  classmethod shebang_from_data(data)
  classmethod shebang_from_path(path)
  get(snippet=False, comments=True)
  banner(description)
  add(data, snippet=True, description=None)
  add_file(path, **kwargs)
  save_as(path, **kwargs)
  update_as(path, **kwargs)

    Like save_as(), but return bool whether file has changed on disk

  save(dir_, **kwargs)
  update(dir_, **kwargs)
  run(cli=False)

class mini_buildd.files.Script(script_path)

  Bases: `File`

  Load a complete script file as `File` (with automatic shebang recognition)

class mini_buildd.files.PerlModule(*args, **kwargs)

  Bases: `File`

class mini_buildd.files.ShellScript(name, description=None, snippet=None, comment='#', shebang=None, finalizer=None, placeholders=None)

  Bases: `File`

  banner(description)

class mini_buildd.files.ShScript(*args, **kwargs)

  Bases: `ShellScript`

class mini_buildd.files.BashScript(*args, **kwargs)

  Bases: `ShellScript`

class mini_buildd.files.AutoScript(path, **kwargs)

  Bases: `File`

class mini_buildd.files.Dir(path=None, enumerate_file_names=-1)

  Bases: `OrderedDict`

  add(file_)
  save(path=None)
  update([E, ]**F) → None. Update D from mapping/iterable E and F.

    If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

class mini_buildd.files.AptLine(mirror, path, suite, components, options=None, comment=None)

  Bases: `object`

  get(type_='deb', mirror=None, options=None)

class mini_buildd.files.SourcesList(iterable=(), /)

  Bases: `list`

  get(types=None, mirror=None, options=None, with_comment=False)