Exemplo n.º 1
0
def _status(info):
    path = os.getcwd()
    if hasattr(info, 'package'):
        pkg = Package(path)
        for filename in sorted(os.listdir(path)):
            print "%s\t%s" % (pkg.status(filename), filename)
    else:
        prj = Project(path)
        for package in sorted(os.listdir(path)):
            print "%s\t%s" % (prj._status(package), package)
Exemplo n.º 2
0
def _status(info):
    path = os.getcwd()
    if hasattr(info, 'package'):
        pkg = Package(path)
        for filename in sorted(os.listdir(path)):
            print "%s\t%s" % (pkg.status(filename), filename)
    else:
        prj = Project(path)
        for package in sorted(os.listdir(path)):
            print "%s\t%s" % (prj._status(package), package)
Exemplo n.º 3
0
    def repair(path, project='', apiurl='', no_packages=False,
               **package_states):
        """Repair a working copy.

        path is the path to the project working copy.

        Keyword arguments:
        project -- the name of the project (default: '')
        apiurl -- the apiurl of the project (default: '')
        no_packages -- do not repair the project's packages (default: False)
        **package_states -- a package to state mapping (default: {})

        """
        global _PKG_DATA
        missing, xml_data, pkg_data = Project.wc_check(path)
        if '_project' in missing:
            if not project:
                raise ValueError('project argument required')
            wc_write_project(path, project)
        if '_apiurl' in missing:
            if not apiurl:
                raise ValueError('apiurl argument required')
            wc_write_apiurl(path, apiurl)
        if '_packages' in missing or xml_data:
            if not package_states:
                raise ValueError('package states required')
            wc_write_packages(path, '<packages/>')
            packages = wc_read_packages(path)
            for package, st in package_states.iteritems():
                packages.add(package, state=st)
            packages.write()
        if '_version' in missing:
            wc_write_version(path)
        if _PKG_DATA in missing:
            os.mkdir(wc_pkg_data_filename(path, ''))
        if not no_packages:
            project = wc_read_project(path)
            apiurl = wc_read_apiurl(path)
            packages = wc_read_packages(path)
            missing, xml_data, pkg_data = Project.wc_check(path)
            # only pkg data left
            for package in pkg_data:
                package_path = os.path.join(path, package)
                if os.path.isdir(package_path):
                    storedir = wc_pkg_data_mkdir(path, package)
                    Package.repair(package_path, project=project,
                                   package=package, apiurl=apiurl,
                                   ext_storedir=storedir)
                else:
                    packages.remove(package)
                    packages.write()
Exemplo n.º 4
0
    def repair(path, project='', apiurl='', no_packages=False,
               **package_states):
        """Repair a working copy.

        path is the path to the project working copy.

        Keyword arguments:
        project -- the name of the project (default: '')
        apiurl -- the apiurl of the project (default: '')
        no_packages -- do not repair the project's packages (default: False)
        **package_states -- a package to state mapping (default: {})

        """
        global _PKG_DATA
        missing, xml_data, pkg_data = Project.wc_check(path)
        if '_project' in missing:
            if not project:
                raise ValueError('project argument required')
            wc_write_project(path, project)
        if '_apiurl' in missing:
            if not apiurl:
                raise ValueError('apiurl argument required')
            wc_write_apiurl(path, apiurl)
        if '_packages' in missing or xml_data:
            if not package_states:
                raise ValueError('package states required')
            wc_write_packages(path, '<packages/>')
            packages = wc_read_packages(path)
            for package, st in package_states.items():
                packages.add(package, state=st)
            packages.write()
        if '_version' in missing:
            wc_write_version(path)
        if _PKG_DATA in missing:
            os.mkdir(wc_pkg_data_filename(path, ''))
        if not no_packages:
            project = wc_read_project(path)
            apiurl = wc_read_apiurl(path)
            packages = wc_read_packages(path)
            missing, xml_data, pkg_data = Project.wc_check(path)
            # only pkg data left
            for package in pkg_data:
                package_path = os.path.join(path, package)
                if os.path.isdir(package_path):
                    storedir = wc_pkg_data_mkdir(path, package)
                    Package.repair(package_path, project=project,
                                   package=package, apiurl=apiurl,
                                   ext_storedir=storedir)
                else:
                    packages.remove(package)
                    packages.write()
Exemplo n.º 5
0
 def test_package1(self):
     """test package convert (added package)"""
     path = self.fixture_file('convert_1')
     self.assertRaises(WCFormatVersionError, Package, path)
     self.assertRaises(WCInconsistentError, Package, path,
                       verify_format=False)
     convert_package(path)
     pkg = Package(path)
     self.assertEqual(pkg.files(), ['add'])
     self.assertEqual(pkg.status('add'), 'A')
     self._exists(path, 'data', store=True)
     self._exists(path, '_version', store=True)
     self._not_exists(path, '_osclib_version', store=True)
     self._not_exists(path, '_to_be_added', store=True)
Exemplo n.º 6
0
def _update(info):
    path = os.getcwd()
    par_path = os.path.join(path, os.pardir)
    expand = ''
    if hasattr(info, 'expand'):
        expand = info.expand
    if hasattr(info, 'package') and not wc_is_project(par_path):
        pkg = Package(path, transaction_listner=[MyTransactionListener()])
        pkg.update(expand=expand)
    elif hasattr(info, 'package') and wc_is_project(par_path):
        prj = Project(par_path, transaction_listener=[MyTransactionListener()])
        prj.update(*[info.package], expand=expand)
    elif wc_is_project(path):
        prj = Project(path, transaction_listener=[MyTransactionListener()])
        prj.update(expand=expand)
Exemplo n.º 7
0
 def test_package3(self):
     """test package convert (deleted storefile missing)"""
     path = self.fixture_file('convert_2_inv')
     self.assertRaises(WCFormatVersionError, Package, path)
     self.assertRaises(WCInconsistentError, Package, path,
                       verify_format=False)
     convert_package(path)
     pkg = Package(path)
     self.assertEqual(pkg.files(), ['conflict', 'missing', 'deleted'])
     self.assertEqual(pkg.status('conflict'), 'C')
     self.assertEqual(pkg.status('missing'), '!')
     self.assertEqual(pkg.status('deleted'), 'D')
     self._exists(path, 'data', store=True)
     self._exists(path, '_version', store=True)
     self._not_exists(path, '_osclib_version', store=True)
Exemplo n.º 8
0
def _update(info):
    path = os.getcwd()
    par_path = os.path.join(path, os.pardir)
    expand = ''
    if hasattr(info, 'expand'):
        expand = info.expand
    if hasattr(info, 'package') and not wc_is_project(par_path):
        pkg = Package(path, transaction_listner=[MyTransactionListener()])
        pkg.update(expand=expand)
    elif hasattr(info, 'package') and wc_is_project(par_path):
        prj = Project(par_path, transaction_listener=[MyTransactionListener()])
        prj.update(*[info.package], expand=expand)
    elif wc_is_project(path):
        prj = Project(path, transaction_listener=[MyTransactionListener()])
        prj.update(expand=expand)
Exemplo n.º 9
0
 def test_package1(self):
     """test package convert (added package)"""
     path = self.fixture_file('convert_1')
     self.assertRaises(WCFormatVersionError, Package, path)
     self.assertRaises(WCInconsistentError,
                       Package,
                       path,
                       verify_format=False)
     convert_package(path)
     pkg = Package(path)
     self.assertEqual(pkg.files(), ['add'])
     self.assertEqual(pkg.status('add'), 'A')
     self._exists(path, 'data', store=True)
     self._exists(path, '_version', store=True)
     self._not_exists(path, '_osclib_version', store=True)
     self._not_exists(path, '_to_be_added', store=True)
Exemplo n.º 10
0
 def test_package3(self):
     """test package convert (deleted storefile missing)"""
     path = self.fixture_file('convert_2_inv')
     self.assertRaises(WCFormatVersionError, Package, path)
     self.assertRaises(WCInconsistentError,
                       Package,
                       path,
                       verify_format=False)
     convert_package(path)
     pkg = Package(path)
     self.assertEqual(pkg.files(), ['conflict', 'missing', 'deleted'])
     self.assertEqual(pkg.status('conflict'), 'C')
     self.assertEqual(pkg.status('missing'), '!')
     self.assertEqual(pkg.status('deleted'), 'D')
     self._exists(path, 'data', store=True)
     self._exists(path, '_version', store=True)
     self._not_exists(path, '_osclib_version', store=True)
Exemplo n.º 11
0
    def package_obj(self, *args, **kwargs):
        """Returns a Package object if possible.

        *args and **kwargs are optional arguments for Package's
        __init__ method. If no Package can be returned None is
        returned.

        """
        if self.package_path is None or not wc_is_package(self.package_path):
            return None
        return Package(self.package_path, *args, **kwargs)
Exemplo n.º 12
0
 def test_package4(self):
     """test package convert (_project file missing)"""
     path = self.fixture_file('convert_2_inv_project')
     self.assertRaises(WCFormatVersionError, Package, path)
     self.assertRaises(WCInconsistentError,
                       Package,
                       path,
                       verify_format=False)
     self._not_exists(path, '_project', store=True)
     self.assertRaises(ValueError, convert_package, path)
     convert_package(path, project='foobar')
     pkg = Package(path)
     self.assertEqual(pkg.project, 'foobar')
     self._exists(path, '_project', store=True)
Exemplo n.º 13
0
    def package(self, package, *args, **kwargs):
        """Return a Package object for package package.

        None is returned if package is missing (has state '!')
        or if package is untracked.

        *args and **kwargs are additional arguments for the
        Package's __init__ method.

        """
        path = os.path.join(self.path, package)
        st = self._status(package)
        if st in ('!', '?') or not wc_is_package(path):
            return None
        return Package(path, *args, **kwargs)
Exemplo n.º 14
0
    def add(self, package, *filenames, **kwargs):
        """Add a new package to the project.

        package is the name of the directory which will be added.
        A ValueError is raised if package is already tracked or if
        package is already an osc working copy.
        Also if prj/package does not exist or is no directory
        a ValueError is raised.
        If filenames are specified they are added to package.
        If no filenames are specified all files will be added
        to the package.
        A ValueError is raised if filenames and no_files=True
        is specified.

        Keyword arguments:
        no_files -- add no files (default: False)

        """
        super(Project, self).add(package)
        no_files = kwargs.get('no_files', False)
        if filenames and no_files:
            raise ValueError("filenames and no_files are mutually exclusive")
        with wc_lock(self.path):
            if self._status(package) != '?':
                raise ValueError("package \"%s\" is already tracked" % package)
            pkg_path = os.path.join(self.path, package)
            if not os.path.isdir(pkg_path):
                raise ValueError("path \"%s\" is no dir" % pkg_path)
            elif wc_is_project(pkg_path) or wc_is_package(pkg_path):
                msg = ("path \"%s\" is already an initialized"
                       "working copy" % pkg_path)
                raise ValueError(msg)
            storedir = wc_pkg_data_mkdir(self.path, package)
            pkg = Package.init(pkg_path, self.name, package, self.apiurl,
                               ext_storedir=storedir)
            self._packages.add(package, state='A')
            self._packages.write()
            if no_files:
                filenames = []
            elif not filenames:
                filenames = [f for f in os.listdir(pkg.path)
                             if os.path.isfile(os.path.join(pkg.path, f))]
            for filename in filenames:
                pkg.add(filename)
Exemplo n.º 15
0
    def add(self, package, *filenames, **kwargs):
        """Add a new package to the project.

        package is the name of the directory which will be added.
        A ValueError is raised if package is already tracked or if
        package is already an osc working copy.
        Also if prj/package does not exist or is no directory
        a ValueError is raised.
        If filenames are specified they are added to package.
        If no filenames are specified all files will be added
        to the package.
        A ValueError is raised if filenames and no_files=True
        is specified.

        Keyword arguments:
        no_files -- add no files (default: False)

        """
        super(Project, self).add(package)
        no_files = kwargs.get('no_files', False)
        if filenames and no_files:
            raise ValueError("filenames and no_files are mutually exclusive")
        with wc_lock(self.path):
            if self._status(package) != '?':
                raise ValueError("package \"%s\" is already tracked" % package)
            pkg_path = os.path.join(self.path, package)
            if not os.path.isdir(pkg_path):
                raise ValueError("path \"%s\" is no dir" % pkg_path)
            elif wc_is_project(pkg_path) or wc_is_package(pkg_path):
                msg = ("path \"%s\" is already an initialized"
                       "working copy" % pkg_path)
                raise ValueError(msg)
            storedir = wc_pkg_data_mkdir(self.path, package)
            pkg = Package.init(pkg_path, self.name, package, self.apiurl,
                               ext_storedir=storedir)
            self._packages.add(package, state='A')
            self._packages.write()
            if no_files:
                filenames = []
            elif not filenames:
                filenames = [f for f in os.listdir(pkg.path)
                             if os.path.isfile(os.path.join(pkg.path, f))]
            for filename in filenames:
                pkg.add(filename)
Exemplo n.º 16
0
 def _perform_adds(self, ustate, **kwargs):
     uinfo = ustate.info
     tl = self.notifier.listener
     for package in uinfo.added:
         tmp_dir = os.path.join(ustate.location, package)
         storedir = wc_pkg_data_filename(self.path, package)
         if ustate.state == UpdateStateMixin.STATE_PREPARE:
             os.mkdir(storedir)
             pkg = Package.init(tmp_dir, self.name, package,
                                self.apiurl, storedir,
                                transaction_listener=tl)
             pkg.update(**kwargs)
             ustate.state = UpdateStateMixin.STATE_UPDATING
         # fixup symlink
         new_dir = os.path.join(self.path, package)
         path = os.path.relpath(storedir, new_dir)
         old_storelink = _storedir(tmp_dir)
         if os.path.isdir(tmp_dir):
             if os.path.exists(old_storelink):
                 os.unlink(old_storelink)
             os.symlink(path, old_storelink)
             os.rename(tmp_dir, new_dir)
         ustate.processed(package, ' ')
         self.notifier.processed(package, ' ', None)
Exemplo n.º 17
0
 def _perform_adds(self, ustate, **kwargs):
     uinfo = ustate.info
     tl = self.notifier.listener
     for package in uinfo.added:
         tmp_dir = os.path.join(ustate.location, package)
         storedir = wc_pkg_data_filename(self.path, package)
         if ustate.state == UpdateStateMixin.STATE_PREPARE:
             os.mkdir(storedir)
             pkg = Package.init(tmp_dir, self.name, package,
                                self.apiurl, storedir,
                                transaction_listener=tl)
             pkg.update(**kwargs)
             ustate.state = UpdateStateMixin.STATE_UPDATING
         # fixup symlink
         new_dir = os.path.join(self.path, package)
         path = os.path.relpath(storedir, new_dir)
         old_storelink = _storedir(tmp_dir)
         if os.path.isdir(tmp_dir):
             if os.path.exists(old_storelink):
                 os.unlink(old_storelink)
             os.symlink(path, old_storelink)
             os.rename(tmp_dir, new_dir)
         ustate.processed(package, ' ')
         self.notifier.processed(package, ' ', None)
Exemplo n.º 18
0
def convert_package(path, ext_storedir=None, **kwargs):
    """Convert working copy to the new format.

    path is the path to the package working copy.

    Keyword arguments:
    project -- name of the project (default: '')
    package -- name of the package (default: '')
    apiurl -- apiurl is the apiurl (default: '')
    ext_storedir -- path to the external storedir (default: None)

    """
    data_path = wc_pkg_data_filename(path, '')
    if not os.path.exists(data_path):
        os.mkdir(data_path)
    if missing_storepaths(path, '_project'):
        project = kwargs.get('project', '')
        if not project:
            raise ValueError('project argument required')
    else:
        project = wc_read_project(path)
    deleted = []
    added = []
    conflicted = []
    if os.path.exists(_storefile(path, '_to_be_deleted')):
        deleted = _read_storefile(path, '_to_be_deleted').split()
        os.unlink(_storefile(path, '_to_be_deleted'))
    if os.path.exists(_storefile(path, '_to_be_added')):
        added = _read_storefile(path, '_to_be_added').split()
        os.unlink(_storefile(path, '_to_be_added'))
    if os.path.exists(_storefile(path, '_in_conflict')):
        conflicted = _read_storefile(path, '_in_conflict').split()
        os.unlink(_storefile(path, '_in_conflict'))
    try:
        files = wc_read_files(path)
    except ValueError:
        files = None
    if files is not None:
        files._xml.set('project', project)
        for entry in files:
            filename = entry.get('name')
            store = _storefile(path, filename)
            data = wc_pkg_data_filename(path, filename)
            if os.path.exists(store):
                os.rename(store, data)
            if filename in added:
                files.set(filename, 'A')
            elif filename in deleted:
                files.set(filename, 'D')
            elif filename in conflicted:
                files.set(filename, 'C')
            else:
                files.set(filename, ' ')
        for filename in added:
            if files.find(filename) is None:
                files.add(filename, 'A')
        files.write()
    if _storefile(path, '_osclib_version'):
        os.unlink(_storefile(path, '_osclib_version'))
    if ext_storedir is not None:
        # move all files to the new location
        storedir = _storedir(path)
        for filename in os.listdir(_storefile(path, '')):
            old = os.path.join(storedir, filename)
            new = os.path.join(ext_storedir, filename)
            os.rename(old, new)
        os.rmdir(storedir)
        os.symlink(os.path.relpath(ext_storedir, path), storedir)
    Package.repair(path, ext_storedir=ext_storedir, **kwargs)
Exemplo n.º 19
0
def convert_package(path, ext_storedir=None, **kwargs):
    """Convert working copy to the new format.

    path is the path to the package working copy.

    Keyword arguments:
    project -- name of the project (default: '')
    package -- name of the package (default: '')
    apiurl -- apiurl is the apiurl (default: '')
    ext_storedir -- path to the external storedir (default: None)

    """
    data_path = wc_pkg_data_filename(path, '')
    if not os.path.exists(data_path):
        os.mkdir(data_path)
    if missing_storepaths(path, '_project'):
        project = kwargs.get('project', '')
        if not project:
            raise ValueError('project argument required')
    else:
        project = wc_read_project(path)
    deleted = []
    added = []
    conflicted = []
    if os.path.exists(_storefile(path, '_to_be_deleted')):
        deleted = _read_storefile(path, '_to_be_deleted').split()
        os.unlink(_storefile(path, '_to_be_deleted'))
    if os.path.exists(_storefile(path, '_to_be_added')):
        added = _read_storefile(path, '_to_be_added').split()
        os.unlink(_storefile(path, '_to_be_added'))
    if os.path.exists(_storefile(path, '_in_conflict')):
        conflicted = _read_storefile(path, '_in_conflict').split()
        os.unlink(_storefile(path, '_in_conflict'))
    try:
        files = wc_read_files(path)
    except ValueError:
        files = None
    if files is not None:
        files._xml.set('project', project)
        for entry in files:
            filename = entry.get('name')
            store = _storefile(path, filename)
            data = wc_pkg_data_filename(path, filename)
            if os.path.exists(store):
                os.rename(store, data)
            if filename in added:
                files.set(filename, 'A')
            elif filename in deleted:
                files.set(filename, 'D')
            elif filename in conflicted:
                files.set(filename, 'C')
            else:
                files.set(filename, ' ')
        for filename in added:
            if files.find(filename) is None:
                files.add(filename, 'A')
        files.write()
    if _storefile(path, '_osclib_version'):
        os.unlink(_storefile(path, '_osclib_version'))
    if ext_storedir is not None:
        # move all files to the new location
        storedir = _storedir(path)
        for filename in os.listdir(_storefile(path, '')):
            old = os.path.join(storedir, filename)
            new = os.path.join(ext_storedir, filename)
            os.rename(old, new)
        os.rmdir(storedir)
        os.symlink(os.path.relpath(ext_storedir, path), storedir)
    Package.repair(path, ext_storedir=ext_storedir, **kwargs)
Exemplo n.º 20
0
def _diff(info):
    path = os.getcwd()
    pkg = Package(path)
    ud = MyUnifiedDiff()
    pkg.diff(ud)
    ud.diff()
Exemplo n.º 21
0
def _diff(info):
    path = os.getcwd()
    pkg = Package(path)
    ud = MyUnifiedDiff()
    pkg.diff(ud)
    ud.diff()